I have this array of arrays. I want it to be sorted by arrays\' length. I use array.sort( (a, b) => a.length > b.length) );
array.sort( (a, b) => a.length > b.length) );
[ [], [ 2, 2,
To do the sort function, you have to provide the max, min equal (+1 (>0 actually), -1 (<0 actually), 0 (for equals)), the faster way is by substract the results:
arr.sort(function(a, b){ // ASC -> a.length - b.length // DESC -> b.length - a.length return a.length - b.length ; });