Created
November 2, 2016 18:01
-
-
Save willgm/f2ccb0d2c0dc7e3f5dd25c81c37b134c 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 mostFrequentIn(array) { | |
const score = array.reduce((m, i) => m.set(i, (m.get(i) || 0) + 1), new Map); | |
return Array.from(score) | |
.reduce( | |
(r, [key, val]) => val > r.val ? {key, val} : r, | |
{key: '', val: 0} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment