Skip to content

Instantly share code, notes, and snippets.

@matthewstokeley
Created May 30, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewstokeley/2ea7f266a2313702579a to your computer and use it in GitHub Desktop.
Save matthewstokeley/2ea7f266a2313702579a to your computer and use it in GitHub Desktop.
compare strings regardless of case
// 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