Skip to content

Instantly share code, notes, and snippets.

@noeldelgado
Last active December 17, 2015 04:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noeldelgado/5550173 to your computer and use it in GitHub Desktop.
Save noeldelgado/5550173 to your computer and use it in GitHub Desktop.
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