Last active
August 29, 2015 14:00
-
-
Save erming/11317321 to your computer and use it in GitHub Desktop.
String.contains.js
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
// | |
// Check if string contains any of the supplied words. | |
// | |
// Usage: | |
// "".contains(a, b, ...); | |
// | |
// Returns [true|false] | |
// | |
String.prototype.contains = function() { | |
var args = arguments; | |
for (var i in args) { | |
var str = args[i]; | |
if (typeof str === "string" && this.indexOf(str) > -1) { | |
return true; | |
} | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment