Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save uzbekdev1/4444c03134a981a357513e84bb0fffd6 to your computer and use it in GitHub Desktop.
Save uzbekdev1/4444c03134a981a357513e84bb0fffd6 to your computer and use it in GitHub Desktop.
JavaScript strcasecmp
//source
function strcasecmp (a, b){
var size = a.length>=b.length?a.length:b.length;
var counter=0;
var aLow=a.toLowerCase();
var bLow=b.toLowerCase();
for(var i=0;i<size;i++){
if((i<=aLow.length || i<=bLow.length) && aLow[i]!=bLow[i]){
counter++;
}
}
return counter;
}
//test
strcasecmp('HELLO', 'hello');
//result
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment