Last active
December 17, 2015 04:28
-
-
Save noeldelgado/5550173 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 orderByHSL = function( x, y ) { | |
var hslx, hsly; | |
var pad = function(value) { | |
var l = value.length; | |
while (l < 3) { | |
l += 1; | |
value = "0" + value; | |
} | |
return value; | |
}; | |
hslx = ( | |
pad( x.h.toString() ) + | |
pad( x.s.toString() ) + | |
pad( x.l.toString() ) | |
); | |
hsly = ( | |
pad( y.h.toString() ) + | |
pad( y.s.toString() ) + | |
pad( y.l.toString() ) | |
); | |
return hslx - hsly; | |
}; | |
/* Assuming you have a colors Array in the following form | |
* mycolors = [ | |
* {"h": 335, "s": 100, "l": 40}, | |
* {"h": 192, "s": 100, "l": 50}, | |
* {"h": 0, "s": 100, "l": 50}, | |
* {"h": 140, "s": 100, "l": 50} | |
* ]; | |
*/ | |
// mycolors.sort( orderByHSL ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment