Created
May 30, 2015 20:49
-
-
Save matthewstokeley/2ea7f266a2313702579a to your computer and use it in GitHub Desktop.
compare strings regardless of case
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
// as a function | |
var isLike = function(set) { | |
if ((set[0].localeCompare(set[1], 'en', {sensitivity: 'base'})) !== 0) { | |
return false; | |
} | |
return true; | |
}; | |
var is = isLike(['a', 'A']); | |
// as a method attached to the string native | |
String.prototype.isLike = function(compare) { | |
if ((this.split()[0].localeCompare(compare, 'en', {sensitivity: 'base'})) !== 0) { | |
return false; | |
} | |
return true; | |
}; | |
var is = 'abc'.isLike('aBc'); | |
// @TODO as a standalone object that string can inherit. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment