N
N
newaitix2018-05-22 15:07:52
JavaScript
newaitix, 2018-05-22 15:07:52

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);
  });
}

IE 11 throws an error
Object does not support property or method "sign"
How to rewrite the code in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anatoly Zharov, 2018-05-22
@newaitix

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 question

Ask a Question

731 491 924 answers to any question