Created
May 2, 2016 21:41
-
-
Save tmcw/2fabba3d46b2db3970cbc4efd273ba01 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var filter = [ | |
"all", | |
[ "in", "$type", "Polygon", "LineString", "Point"], | |
[ "all", | |
["in", "type", "town", "city"], | |
["==", "class", "street_limited"], | |
[ "<=", "scalerank", 2] | |
] | |
] | |
var filter2 = [ | |
"all", | |
[ "in", "$type", "Polygon", "Point", "LineString"], | |
[ "all", | |
["in", "type", "city", "town"], | |
["==", "class", "street_limited"], | |
[ "<=", "scalerank", 2] | |
] | |
] | |
var filter3 = [ | |
"all", | |
[ "all", | |
["in", "type", "city", "town"], | |
["==", "class", "street_limited"], | |
[ "<=", "scalerank", 2] | |
], | |
[ "in", "$type", "Polygon", "Point", "LineString"] | |
] | |
var filter4 = [ | |
"all", | |
[ "all", | |
["==", "class", "street_limited"], | |
["in", "type", "city", "town"], | |
[ "<=", "scalerank", 2] | |
], | |
[ "in", "$type", "Polygon", "Point", "LineString"] | |
] | |
var filter5 = [ | |
"all", | |
[ "all", | |
["==", "class", "street_limited"], | |
["in", "type", "city", "town"], | |
[ "<=", "scalerank", 2] | |
], | |
[ "in", "$type", "Polygon", "Point", "LineString"] | |
] | |
function sortLevel(list) { | |
if (!Array.isArray(list)) { | |
return list; | |
} else if (list[0] == 'any' || list[0] == 'all' || list[0] == 'none') { | |
return list.slice(0, 1).concat(list.slice(1).map(sortLevel).sort()); | |
} else { | |
return list.slice(0, 2).concat(list.slice(2).map(sortLevel).sort()); | |
} | |
} | |
console.log(sortLevel(filter)); | |
console.log(sortLevel(filter2)); | |
console.log(sortLevel(filter3)); | |
console.log(sortLevel(filter4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment