Skip to content

Instantly share code, notes, and snippets.

@leeoniya
Created June 19, 2013 18:09
Show Gist options
  • Save leeoniya/5816476 to your computer and use it in GitHub Desktop.
Save leeoniya/5816476 to your computer and use it in GitHub Desktop.
test if js engine's Array#sort implementation is stable
// test if js engine's Array#sort implementation is stable
var str = "abcdefghijklmnopqrstuvwxyz";
str.split("").sort(function(a,b) {
return ~~(str.indexOf(b)/2.3) - ~~(str.indexOf(a)/2.3);
}).join("") == "xyzvwtursopqmnklhijfgdeabc";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment