Initial commit
[yaffs-website] / node_modules / find-index / index.js
1 function findIndex(array, predicate, self) {
2   var len = array.length;
3   var i;
4   if (len === 0) return -1;
5   if (typeof predicate !== 'function') {
6     throw new TypeError(predicate + ' must be a function');
7   }
8
9   if (self) {
10     for (i = 0; i < len; i++) {
11       if (predicate.call(self, array[i], i, array)) {
12         return i;
13       }
14     }
15   } else {
16     for (i = 0; i < len; i++) {
17       if (predicate(array[i], i, array)) {
18         return i;
19       }
20     }
21   }
22
23   return -1;
24 }
25
26 module.exports = findIndex