const fs = require('fs'); const optimum = 500; function find(path) { let output = []; for (let content of fs.readdirSync(path, {withFileTypes: true})) { if (content.isDirectory()) { output.push(...find(path + '/' + content.name)); } else { output.push(path + '/' + content.name); } } return output; } function optimizeCurve(path) { let input = fs.readFileSync(path, 'utf-8') .split('\n') .map((x) => x.split(' ')); let output = [input[0]]; let step = Math.floor(input.length / optimum); for (let i = 1; i < input.length; i += step) { output.push(input[i]); } fs.writeFileSync(path.slice(0, - '-full.dat'.length) + '.dat', output.map((x) => x.join(' ')).join('\n')); } for (let file of find('.')) { if (file.endsWith('-full.dat')) { optimizeCurve(file); } }