I am having a set of strings in array, and by pure javascript I am trying to sort them and print them out. I am only getting blank array. Can someone help me out?
<script>
(function(){
var a = ["AB", "SU", "MN", "AC", "QA", "DZ", "CM", "EP"];
var b = [];
for(i=0;i<a.length;i++){
var temp = a[i].split('')[0];
for(j=0;j<b.length;j++){
if (temp < b[j].split('')[0]){
b[j] = push(a[i]);
}
}
}
console.log(b);
})();
</script>
Also I need to take in account comparision of second, third, fourth characters if they exist, but I am doomed even in fist letter comparison in string. Pls, take that also in account.
Array.prototype.sortmethod.a[i] < b[j].