Skip to content

Instantly share code, notes, and snippets.

@ealipio
Created September 25, 2019 04:18
Embed
What would you like to do?
get the most repeated number in an array
arr = [12, 10, 8, 12, 7, 6, 4, 10, 12];
const unique = [...new Set(arr)]
let obj = {};
for(let i=0;i<arr.length;i++) {
obj[arr[i]] = (obj[arr[i]] || 0 )+1
}
const max = Math.max(...Object.values(obj))
const [highFreq] = unique.filter(i => obj[i] === max)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment