Created
July 6, 2016 20:55
-
-
Save Joncom/59856f30f351510a656b3ffbf5ec633f to your computer and use it in GitHub Desktop.
Sorting An Array By Multiple Criteria
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
ig.game.backgroundMaps.sort(function(a,b) { | |
var o1 = (a.repeat ? 0 : 1); | |
var o2 = (b.repeat ? 0 : 1); | |
var p1 = (a.foreground ? 1 : 0); | |
var p2 = (b.foreground ? 1 : 0); | |
if(o1 === o2) { | |
return (p1 < p2) ? -1 : (p1 > p2) ? 1 : 0; | |
} else { | |
return (o1 < o2) ? -1 : 1; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment