Açıklama Yok

index.js 512B

1234567891011121314151617181920212223242526
  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. if (self) {
  9. for (i = 0; i < len; i++) {
  10. if (predicate.call(self, array[i], i, array)) {
  11. return i;
  12. }
  13. }
  14. } else {
  15. for (i = 0; i < len; i++) {
  16. if (predicate(array[i], i, array)) {
  17. return i;
  18. }
  19. }
  20. }
  21. return -1;
  22. }
  23. module.exports = findIndex