Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8f83659

Browse files
committed
Merge pull request #1 from timdp/patch-1
Throw on invalid predicate even if array is empty
2 parents 01afc1e + a962327 commit 8f83659

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ module.exports = function (arr, predicate, ctx) {
44
return arr.findIndex(predicate, ctx);
55
}
66

7+
if (typeof predicate !== 'function') {
8+
throw new TypeError('predicate must be a function');
9+
}
10+
711
var list = Object(arr);
812
var len = list.length;
913

1014
if (len === 0) {
1115
return -1;
1216
}
1317

14-
if (typeof predicate !== 'function') {
15-
throw new TypeError('predicate must be a function');
16-
}
17-
1818
for (var i = 0; i < len; i++) {
1919
if (predicate.call(ctx, list[i], i, list)) {
2020
return i;

0 commit comments

Comments
 (0)