Skip to content

Instantly share code, notes, and snippets.

@benjamingr
Created May 16, 2018 21:24
Show Gist options
  • Save benjamingr/1420748ba1a85e380f9879120714a0b9 to your computer and use it in GitHub Desktop.
Save benjamingr/1420748ba1a85e380f9879120714a0b9 to your computer and use it in GitHub Desktop.
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