I am looking for a concise JavaScript function which takes some values and returns the unique values sorted by the number of occurrences, the most frequent first.
For example, if the input is the array [3,2,2,2,2,1,2,1] then the output should be [2,1,3].
Here’s my first stab. I bet we can make it simpler, but this seems okay.