Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Hmm... solution in Clear category for Sort Array by Element Frequency by akaka
function frequencySort(items: any[]): any[] {
const count = (t) => items.filter(i => i === t).length
return [... new Set(items)]
.sort((a, b) => count(b) - count(a))
.reduce(
(ac, cr) => [...ac, ...new Array(count(cr)).fill(cr)], []
)
}
May 27, 2020
Comments: