0
function countRepetitions(arr) {
    const counts = arr.reduce((a, c) => **(a[c] = (a[c] || 0) + 1, a)**, {});
    return Object.fromEntries(Object.entries(counts).sort((a, b) => b[1] - a[1]));
}

FYI, I know how reduce function works.

0 Answers0