Skip to content

Instantly share code, notes, and snippets.

@Williammer
Created June 4, 2014 10:34
Show Gist options
  • Select an option

  • Save Williammer/b7ccaca6486ccac6d22d to your computer and use it in GitHub Desktop.

Select an option

Save Williammer/b7ccaca6486ccac6d22d to your computer and use it in GitHub Desktop.
jsPatterns.revelation.js
(function () {
var astr = "[object Array]",
toString = Object.prototype.toString;
function isArray(a) {
return toString.call(a) === astr;
}
function indexOf(haystack, needle) {
var i = 0,
max = haystack.length;
for (; i < max; i += 1) {
if (haystack[i] === needle) {
return i;
}
}
return -1;
}
myarray = {
isArray: isArray,
indexOf: indexOf,
inArray: indexOf
};
}());
myarray.indexOf = null;
alert(myarray.inArray(["a", "b", "z"], "z")); // 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment