-
-
Save AlexZeitler/5aaf09356ef20300e10f6feb49d09fb8 to your computer and use it in GitHub Desktop.
Node.js - CPU bound operations with Rx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const RxNode = require('rx-node'); | |
const Rx = require('rx'); | |
const spawn = require('child_process').spawn; | |
RxNode.fromStream(spawn('find', ['/','-type','f','-exec', 'cat', '{}', '\+']).stdout) | |
.map(x => x.toString()) | |
.map(x => RxNode.fromStream(spawn('./word-count.js', [x]).stdout)) | |
.mergeAll() | |
.map(x => x.toString()) | |
.do(x => console.log(x)) | |
.subscribe(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
const index = {}; | |
process.argv[2] | |
.replace(/[.,?!;()"'-]/g, ' ') | |
.replace(/\s+/g, ' ') | |
.toLowerCase() | |
.split(' ') | |
.forEach(function (word) { | |
if (!(index.hasOwnProperty(word))) index[word] = 0; | |
index[word]++; | |
}); | |
console.log(index) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment