Created
July 4, 2013 07:34
-
-
Save chakrit/5925648 to your computer and use it in GitHub Desktop.
rx vs indexOf test
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
assert = require 'assert' | |
words = 'apple|orange|pear|banana|kiwi'.split '|' | |
strings = | |
noMatch : "The quick brown fox jumps over the lazy dog." | |
startMatch : "An apple is nice" | |
endMatch : "This is a longer sentence with the match for our fruit at the end: kiwi apple orange pear banana" | |
accept = (str) -> | |
for word in words | |
if (str.indexOf word) isnt -1 | |
return true | |
return false | |
# comment out these blocks to test out indexOf search | |
rx = /(apple|orange|pear|banana|kiwi)/g | |
accept = (str) -> rx.test str | |
for i in [0..1000000] | |
for word in words | |
assert not accept strings.noMatch | |
assert accept strings.startMatch | |
assert accept strings.endMatch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment