项目原始demo,不改动
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 

26 rivejä
464 B

  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. };