Created
May 2, 2015 22:45
-
-
Save dazld/b181e95c07e8350572ef 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 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