Newer
Older
dmpopidor / app / javascript / utils / array.js
@Bodacious Bodacious on 19 Oct 2018 482 bytes Update asset structure with webpacker gem
import { isFunction } from './isType';

if (!Array.prototype.find) {
  Array.prototype.find = function (predicate) { // eslint-disable-line no-extend-native, func-names
    if (!isFunction(predicate)) {
      throw new TypeError('predicate must be a function');
    }
    const array = Object(this);
    let i = 0;
    while (i < array.length) {
      if (predicate.call(this, array[i], i, array)) {
        return array[i];
      }
      i += 1;
    }
    return undefined;
  };
}