-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
implementation.js
32 lines (27 loc) · 896 Bytes
/
implementation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
var Call = require('es-abstract/2024/Call');
var Get = require('es-abstract/2024/Get');
var IsCallable = require('es-abstract/2024/IsCallable');
var LengthOfArrayLike = require('es-abstract/2024/LengthOfArrayLike');
var ToBoolean = require('es-abstract/2024/ToBoolean');
var ToObject = require('es-object-atoms/ToObject');
var ToString = require('es-abstract/2024/ToString');
module.exports = function findIndex(predicate) {
var O = ToObject(this);
var len = LengthOfArrayLike(O);
if (!IsCallable(predicate)) {
throw new TypeError('Array#findIndex: predicate must be a function');
}
var thisArg = arguments.length > 1 ? arguments[1] : void undefined;
var k = 0;
while (k < len) {
var Pk = ToString(k);
var kValue = Get(O, Pk);
var testResult = ToBoolean(Call(predicate, thisArg, [kValue, k, O]));
if (testResult) {
return k;
}
k += 1;
}
return -1;
};