Sort by content
In this task, we are sorting a heterogeneous list of elements. The elements are either single numbers or sequences of numbers. We should sort them by numeric content, like this:
(sort-by-content [4 5 3 2 1]) ;=> [1 2 3 4 5]
;; we sort sequences by their first element, then by second element, then by third, etc
(sort-by-content [[2 3] [0 9] [-1 3 4] [0 3]]) ;=> [[-1 3 4] [0 3] [0 9] [2 3]]
;; we sort numbers and sequences together as if numbers were sequences of length 1
(sort-by-content [5 [4 5] 3 1 [0 2 3]]) ;=> [[0 2 3] 1 3 [4 5] 5]
;; but numbers sort before sequences when the number is the same as the first element
(sort-by-content [[1] 1]) ;=> [1 [1]]
;; don't sort subsequences
(sort-by-content [[10 3 4 1]]) ;=> [[10 3 4 1]]
Update: Someone asked if you need to sort the numbers in subsequences. You do not. Just sort the top-level values, the mix of numbers and sequences of numbers. I've added an example to clarify.
Thanks to this site for the challenge idea where it is considered Medium level in JavaScript.
Please submit your solutions as comments on this gist.