source: imaps-frontend/node_modules/array.prototype.findlast/implementation.js

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
3var $TypeError = require('es-errors/type');
4
5var Call = require('es-abstract/2024/Call');
6var Get = require('es-abstract/2024/Get');
7var IsCallable = require('es-abstract/2024/IsCallable');
8var LengthOfArrayLike = require('es-abstract/2024/LengthOfArrayLike');
9var ToBoolean = require('es-abstract/2024/ToBoolean');
10var ToObject = require('es-object-atoms/ToObject');
11var ToString = require('es-abstract/2024/ToString');
12
13module.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.