Skip to content

Instantly share code, notes, and snippets.

@stoimen
Last active August 29, 2015 14:10
Show Gist options
  • Save stoimen/01edc5c3fdaca4f1764e to your computer and use it in GitHub Desktop.
Save stoimen/01edc5c3fdaca4f1764e to your computer and use it in GitHub Desktop.
Sequential Search (js)
(function() {
var sequential = function(haystack, needle) {
var i = 0,
len = haystack.length
;
for (; i < len; i++) {
if (haystack[i] === needle) {
return true;
}
}
return false;
};
})();
(function() {
var sequential_v1 = function(haystack, needle) {
return haystack.filter(function(element) {
return element === needle
}).length > 0;
};
})();
(function() {
var search = function(haystack, needle) {
var l = haystack.length;
while (haystack[--l] !== needle);
return l > -1;
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment