I already know how to get a element that appears the most in array but now I have a case where I need to get top 5 elements that appears most in the array.
I have this array:
[
"fuji",
"acros",
"bombshell",
"4za",
"aerozine",
"bianchi-milano",
"bianchi-milano",
"aerozine",
"rapha",
"rapha",
"rapha",
"100%",
"100%",
"100%",
"100%"
];
So top five should be:
[
"100%",
"rapha",
"bianchi-milano",
"aerozine",
"fuji" // This one can be random as all the rest appears only once
]
And this is the code that I have for finding one that is duplicating the most:
array.sort( (a, b) => arr.filter(v => v === a).length - arr.filter(v => v === b).length ) .pop();
Any help but also a clarification would mean a lot! Thanks!!