Innovenergy_trunk/frontend/node_modules/array-find/find.js

24 lines
478 B
JavaScript
Raw Normal View History

'use strict';
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;