Skip to content

Instantly share code, notes, and snippets.

@benjamingr benjamingr/sample.js
Created May 16, 2018

Embed
What would you like to do?
function cleanUp (arr, max) {
const cnts = {} // keep track of what we find
return arr.reduce((a, i) => { // loop over the array index by index
cnts[i] = (cnts[i] || 0) + 1; // mark that I seen the number
if (cnts[i] <= max) { // check to see if we are under the max
return a.concat(i) //if we are, add it to an arry
}
return a // return the array for reduce
}, [])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.