main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
950 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var $TypeError = require('es-errors/type');
|
---|
4 |
|
---|
5 | var Call = require('es-abstract/2024/Call');
|
---|
6 | var Get = require('es-abstract/2024/Get');
|
---|
7 | var IsCallable = require('es-abstract/2024/IsCallable');
|
---|
8 | var LengthOfArrayLike = require('es-abstract/2024/LengthOfArrayLike');
|
---|
9 | var ToBoolean = require('es-abstract/2024/ToBoolean');
|
---|
10 | var ToObject = require('es-object-atoms/ToObject');
|
---|
11 | var ToString = require('es-abstract/2024/ToString');
|
---|
12 |
|
---|
13 | module.exports = function findLast(predicate) {
|
---|
14 | var O = ToObject(this);
|
---|
15 | var len = LengthOfArrayLike(O);
|
---|
16 |
|
---|
17 | if (!IsCallable(predicate)) {
|
---|
18 | throw new $TypeError('predicate must be a function');
|
---|
19 | }
|
---|
20 |
|
---|
21 | var thisArg;
|
---|
22 | if (arguments.length > 1) {
|
---|
23 | thisArg = arguments[1];
|
---|
24 | }
|
---|
25 |
|
---|
26 | var k = len - 1;
|
---|
27 | while (k >= 0) {
|
---|
28 | var Pk = ToString(k);
|
---|
29 | var kValue = Get(O, Pk);
|
---|
30 | var testResult = ToBoolean(Call(predicate, thisArg, [kValue, k, O]));
|
---|
31 | if (testResult) {
|
---|
32 | return kValue;
|
---|
33 | }
|
---|
34 | k -= 1;
|
---|
35 | }
|
---|
36 |
|
---|
37 | return void undefined;
|
---|
38 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.