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
// 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 |