Created
May 8, 2014 21:41
-
-
Save unixpickle/0cf97ca78e521ef4d478 to your computer and use it in GitHub Desktop.
Count occurrences of a line in a file
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
fs = require 'fs' | |
fs.readFile 'letters.txt', (err, buffer) -> processFile buffer.toString() | |
processFile = (s) -> | |
counts = {} | |
lines = s.split '\n' | |
for line in lines | |
if counts[line]? | |
counts[line]++ | |
else | |
counts[line] = 1 | |
console.log JSON.stringify counts, null, 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment