Skip to content

Instantly share code, notes, and snippets.

@dazld
Created May 2, 2015 22:45
Show Gist options
  • Save dazld/b181e95c07e8350572ef to your computer and use it in GitHub Desktop.
Save dazld/b181e95c07e8350572ef to your computer and use it in GitHub Desktop.
var strs = ['zz','ee','DD','dd','PP'];
function sortFirstLetter (a,b){
a = a.toLowerCase().charCodeAt(0);
b = b.toLowerCase().charCodeAt(0);
if (a === b) {return 0;}
else if (a > b) {return 1;}
else {return -1;}
}
var times = 10;
while (times){
strs.sort(sortFirstLetter);
console.log(strs)
times--;
}
console.log(' -- reset counter, freeze then try to sort again');
times = 10;
Object.freeze(strs);
while (times){
strs.sort(sortFirstLetter);
console.log(strs)
times--;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment