Sort the distinct elements of a list in descending order by frequency Write a function which takes a list or array, and returns a list of the distinct elements, sorted in descending order by frequency.

Example:

Given:

["John","Doe","Dick","Harry","Harry","Doe","Doe","Harry","Doe","John"]


Expected return value:

["Doe","Harry","John","Dick"]
APL (14)

{∪⍵[⍒+⌿∘.≡⍨⍵]}


This is a function that takes a list, e.g.:

      names
 John  Doe  Dick  Harry  Harry  Doe  Doe  Harry  Doe  John 
      {∪⍵[⍒+⌿∘.≡⍨⍵]} names
 Doe  Harry  John  Dick


Explanation:


∘.≡⍨⍵: compare each element in the array to each other element in the array, giving a matrix
+⌿: sum the columns of the matrix, giving how many times each element occurs
⍒: give indices of downward sort
⍵[...]: reorder ⍵ by the given indices
∪: get the unique elements