Skip to content

Instantly share code, notes, and snippets.

@DevCodo
Created April 7, 2019 14:08
Show Gist options
  • Select an option

  • Save DevCodo/16376de1ed668a0b35b25643c6f080f8 to your computer and use it in GitHub Desktop.

Select an option

Save DevCodo/16376de1ed668a0b35b25643c6f080f8 to your computer and use it in GitHub Desktop.
// Array.prototype.findIndex
if (!Array.prototype.findIndex) {
Array.prototype.findIndex = function(predicate) {
if (this == null) {
throw new TypeError('Array.prototype.findIndex called on null or undefined');
}
if (typeof predicate !== 'function') {
throw new TypeError('predicate must be a function');
}
var list = Object(this);
var length = list.length >>> 0;
var thisArg = arguments[1];
var value;
for (var i = 0; i < length; i++) {
value = list[i];
if (predicate.call(thisArg, value, i, list)) {
return i;
}
}
return -1;
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment