Skip to content

Instantly share code, notes, and snippets.

// input array
a = [ 5, 14, 6, 7, 7, 7, 20, 10, 10 ]
// build an associative array with each number and count how many times it appears in the input array
b = { }, a.forEach ((x) => { b[x] = (b[x]|0)+1;})
// search for the one with maximum count
c = Object.keys (b).map ((x) => b[x])
d = Math.max.apply (Math, c)
e = c.indexOf (d)
f = Object.keys (b)[e]
// output result