I have a list whose members are nested lists of integers, for example :
[ [1,2], [], [1,2,3], [ [1,2],3], [1,2,4], [ [], [1,2] ], [34,5,6], [-1,66] ]
I want to sort this list, using (what every other language in the world) would consider standard ordering of nested lists. For example :
[] < [ [1] ] < [ [1,2] ] < [ [2] ] < [ [11] ]
l.sort() messes this up, because it turns the lists into strings
Is there an easy way, either in javascript (or a common library like lodash) to get a proper sort of nested lists?
_.sort()in either version 2, 3 or 4 - which function specifically are you using?parseIntin your comparer or map with parseInt beforehand.[1, [2, 3], 4]would be larger than[1, [2], 3, 4]or not. Do you just want to flatten them?