I have an array of numeric arrays.
Each numeric array is always an ascending sequence, eg [8, 9, 10].
I want to sort each numeric array based on:
- The first (and lowest) number in the array.
- Their range.
For example, given the following:
[
[1],
[2, 3],
[10],
[11, 12, 13],
[3, 4],
[2, 3, 4],
[1, 2, 3, 4, 5, 6],
[10, 11, 12],
[7, 8, 9],
[1, 2, 3],
[10, 11],
]
The result should be:
[
[1],
[1, 2, 3],
[1, 2, 3, 4, 5, 6],
[2, 3],
[2, 3, 4],
[3, 4],
[7, 8, 9],
[10],
[10, 11],
[10, 11, 12],
[11, 12, 13],
]
The result is very nearly achieved using:
arr.sort((a, b) => a[0] - b[0]);
but not quite.
Here is my example code: https://repl.it/repls/MadeupMediumpurpleCavy
Is there a way I can achieve this using Array.prototype.sort?