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