Re:JS1k demo: “Highway at Night”
by nmjohn on Sunday November 23, 2014 @07:44PM
(#8650541)
> ~x.indexOf(…) would be “starts with” rather than “contains”, for negative numbers such as -2 (from ~1) are truthy.
Nope, here's an example you can run it run in your console:
function contains(needle, haystack) {
return Boolean(~haystack.indexOf(needle));
}
var haystack = "The quick brown fox jumps over the lazy dog";
console.log(contains("The", haystack));
console.log(contains("dog", haystack));
console.log(contains("brown fox jumps", haystack));
Nope, here's an example you can run it run in your console:
Here are three potential cases: