Created
June 6, 2018 17:27
-
-
Save tejashah88/bdd833a8d686203094ccd4245f6f6255 to your computer and use it in GitHub Desktop.
An ES6 function to compute the mode(s) of an array. All modes found will return
This file contains 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
// Credits go to @Anjuna5 for original code: https://stackoverflow.com/a/39838257/9779148 | |
const mode = arr => [...new Set(arr)] | |
.map(value => [value, arr.filter((v) => v === value).length]) | |
.sort((a,b) => b[1] - a[1]) | |
.filter((v, i, a) => v[1] === a[0][1]) | |
.map(v => v[0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment