Skip to content

Instantly share code, notes, and snippets.

@sikanrong
Created July 30, 2018 15:10
Show Gist options
  • Select an option

  • Save sikanrong/ac5b37f21b905a02360286d328a1bea3 to your computer and use it in GitHub Desktop.

Select an option

Save sikanrong/ac5b37f21b905a02360286d328a1bea3 to your computer and use it in GitHub Desktop.
//Microsoft Interview Question
function stricmp(a, b){
var i = 0;
var aAscii, bAscii;
while(!isNaN(a.charCodeAt(i)) && !isNaN(b.charCodeAt(i))){
aAscii = a.charCodeAt(i);
bAscii = b.charCodeAt(i);
i++;
if(aAscii == bAscii || (aAscii ^ 32) == bAscii){
continue;
}else{
break;
}
}
i--; //rewind to the last index before loop broke;
aAscii = a.charCodeAt(i);
bAscii = b.charCodeAt(i);
if(aAscii == bAscii)
return 0;
if((aAscii | 32) < (bAscii | 32))
return -1;
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment