Last active
October 12, 2017 15:33
-
-
Save simontraill/80ea6b7049cbea6563f87ffa9abf82e5 to your computer and use it in GitHub Desktop.
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
var readline = require('readline'); | |
function myAssigner(item) { | |
return (item >= 100)? 10: item % 10; | |
} | |
function BucketReport(count,assigner,scorer) { | |
return { | |
buckets: new Array(count).fill(0), | |
add: function(i) { | |
var b = assigner(i); | |
this.buckets[b] = scorer(this.buckets[b],i); | |
} | |
} | |
} | |
var rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
terminal: false | |
}); | |
var h = BucketReport(11,myAssigner,function(x,y) { return x + y }); | |
rl.on('line', function(line){ | |
h.add(parseInt(line.trim())); | |
}) | |
rl.on('close',function() { | |
console.log(JSON.stringify(h.buckets)); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment