We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Processor Name: Intel Core i5 Processor Speed: 2.3 GHz Number of Processors: 1 Total Number of Cores: 2 L2 Cache (per Core): 256 KB L3 Cache: 4 MB Memory: 16 GB
const fs = require('fs') const path = require('path') const readline = require('readline') const basePath = '<path-to-files-directory>' const getFiles = () => { return new Promise((resolve, reject) => { fs.readdir(basePath, (err, folders) => { if (err) { reject(err) } else { resolve( Promise.all(folders.map(dir => { const dirPath = path.join(basePath, dir) return new Promise((resolve, reject) => { fs.readdir(dirPath, (err, files) => { if (err) { reject(err) } else { resolve(files.map(file => path.join(dirPath, file))) } }) }) })).then(files => files.reduce((a, b) => a.concat(b))) ) } }) }) } console.time('total') let total = 0 getFiles() .then(function* (files) { for (let file of files) { yield new Promise((resolve, reject) => { const lineReader = readline.createInterface({ input: fs.createReadStream(file) }) let fileSum = 0 lineReader.on('line', line => { let lineSum = 0 let current = 0 for(let i = 0; i < line.length; i++) { let char = line[i] if (char != ',' ) { if (current === 0) { current = +char } else { current = (current * 10) + (+char) } } if ((char === ',') || (i === (line.length - 1))) { lineSum += current current = 0 } } fileSum += lineSum }) lineReader.on('close', () => { total += fileSum resolve(fileSum) }) }) } }) .then(sums => { return Promise.all(sums) }) .then(() => { console.log(total) console.timeEnd('total') }) .catch(err => { console.error(err) })
The text was updated successfully, but these errors were encountered:
No branches or pull requests
The text was updated successfully, but these errors were encountered: