const arr = [1,2,2,2,4]
const mostFrequentNum = Array
.from(arr.reduce((acc, n) => acc.set(n, -~acc.get(n)), new Map))
.reduce((max, n) => max[1] > n[1] ? max : n, [ , 0 ])
.at(0);
const mostFrequentNum = Object
.entries(arr.reduce((acc, n) => (acc[n] = (acc[n] ?? 0) + 1, acc), {}))
.reduce((acc, n) => (acc[n[1]] = +n[0], acc), [])
.pop();
a = [1,2,3,5,7,8,3,2,5,7,6,3,1,5,4,2,3,4,4,5,6,2,1,3,4,1,2,3,2,3,4,1,4,2,2,3,4,1,2,3,4]
b = {}
for(x of a){
if(b[x]){
b[x] = b[x]+1;
}
else{
b[x] = 1;
}
}
let maxKey, maxValue = 0;
for(const [key, value] of Object.entries(b)) {
if(value > maxValue) {
maxValue = value;
maxKey = key;
}
}
console.log(`Ключ ${maxKey} имеет больше всего повторений - ${maxValue}`);