Skip to content

Instantly share code, notes, and snippets.

@bmpvieira
Created November 21, 2014 15:10
Show Gist options
  • Save bmpvieira/989778458e886790143f to your computer and use it in GitHub Desktop.
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
#!/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