Created
May 10, 2018 07:37
-
-
Save uzbekdev1/4444c03134a981a357513e84bb0fffd6 to your computer and use it in GitHub Desktop.
JavaScript strcasecmp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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