Skip to content

Instantly share code, notes, and snippets.

@willgm
Created November 2, 2016 18:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save willgm/f2ccb0d2c0dc7e3f5dd25c81c37b134c to your computer and use it in GitHub Desktop.
Save willgm/f2ccb0d2c0dc7e3f5dd25c81c37b134c to your computer and use it in GitHub Desktop.
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