kitchensink
Version:
Dispatch's awesome components and style guide
24 lines (18 loc) • 478 B
JavaScript
;
function find(array, predicate, context) {
if (typeof Array.prototype.find === 'function') {
return array.find(predicate, context);
}
context = context || this;
var length = array.length;
var i;
if (typeof predicate !== 'function') {
throw new TypeError(predicate + ' is not a function');
}
for (i = 0; i < length; i++) {
if (predicate.call(context, array[i], i, array)) {
return array[i];
}
}
}
module.exports = find;