Answer the question
In order to leave comments, you need to log in
How to rewrite code for IE?
function charIndexSort(a,m){
a=a.toLowerCase();
return m.slice(0).sort(function(name1,name2){
let i1=name1.toLowerCase().indexOf(a);
let i2=name2.toLowerCase().indexOf(a);
if(i1<0)return 1;
if(i2<0)return -1;
return Math.sign(i1-i2);
});
}
Answer the question
In order to leave comments, you need to log in
function charIndexSort(a,m){
a=a.toLowerCase();
return m.slice(0).sort(function(name1,name2){
let i1=name1.toLowerCase().indexOf(a);
let i2=name2.toLowerCase().indexOf(a);
if(i1<0)return 1;
if(i2<0)return -1;
return 0;
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question