Deviopath › TypeScript

Sorted Frequency Table

Medium · Arrays & Tuples

Write frequencies<T extends string | number>(items: T[]): [T, number][] that counts each value and returns [value, count] tuples.

Sort by count, highest first. Values with the same count stay in order of first appearance. A Map<T, number> keeps insertion order, which helps here.

Next: Generic uniqueBy