Created
November 21, 2014 15:10
-
-
Save bmpvieira/989778458e886790143f to your computer and use it in GitHub Desktop.
Filter number of repeated elements in a text file list based on minimum number
This file contains hidden or 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 | |
// Usage: ./filterRepeats.js <minimum> <file path> | |
// Example: ./filterRepeats.js 10 list.txt | |
var fs = require('fs') | |
var min = process.argv[2] | |
var listPath = process.argv[3] | |
var list = fs.readFileSync(listPath, 'utf8').split('\n') | |
var counter = {} | |
list.forEach(count) | |
function count(name) { | |
if (!counter[name]) { counter[name] = 0 } | |
counter[name]++ | |
} | |
Object.keys(counter).forEach(printHigh) | |
function printHigh(name) { | |
if (counter[name] >= min) { | |
console.log(name) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment