You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 464B

12345678910111213141516171819202122232425
  1. 'use strict';
  2. module.exports = function (arr, predicate, ctx) {
  3. if (typeof Array.prototype.findIndex === 'function') {
  4. return arr.findIndex(predicate, ctx);
  5. }
  6. if (typeof predicate !== 'function') {
  7. throw new TypeError('predicate must be a function');
  8. }
  9. var list = Object(arr);
  10. var len = list.length;
  11. if (len === 0) {
  12. return -1;
  13. }
  14. for (var i = 0; i < len; i++) {
  15. if (predicate.call(ctx, list[i], i, list)) {
  16. return i;
  17. }
  18. }
  19. return -1;
  20. };