Created
April 12, 2016 15:01
-
-
Save jbnv/70742084803974dcf4d67c507f0a506c to your computer and use it in GitHub Desktop.
String prototype function that matches a sequence to a string if the string contains all characters in the sequence. (E.g. "love" matches "like a glove")
This file contains hidden or 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
if (!String.prototype.matchesSequence) { | |
String.prototype.matchesSequence = function(sequence) { | |
if (!sequence) return false; | |
if (sequence === "") return true; | |
var pattern = sequence.split("").join(".*"); | |
var exp = new RegExp(pattern); | |
return exp.test(this); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment