implementation.js 939 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. 'use strict';
  2. var $TypeError = require('es-errors/type');
  3. var Call = require('es-abstract/2023/Call');
  4. var Get = require('es-abstract/2023/Get');
  5. var IsCallable = require('es-abstract/2023/IsCallable');
  6. var LengthOfArrayLike = require('es-abstract/2023/LengthOfArrayLike');
  7. var ToBoolean = require('es-abstract/2023/ToBoolean');
  8. var ToObject = require('es-abstract/2023/ToObject');
  9. var ToString = require('es-abstract/2023/ToString');
  10. module.exports = function findLastIndex(predicate) {
  11. var O = ToObject(this);
  12. var len = LengthOfArrayLike(O);
  13. if (!IsCallable(predicate)) {
  14. throw new $TypeError('predicate must be a function');
  15. }
  16. var thisArg;
  17. if (arguments.length > 1) {
  18. thisArg = arguments[1];
  19. }
  20. var k = len - 1;
  21. while (k >= 0) {
  22. var Pk = ToString(k);
  23. var kValue = Get(O, Pk);
  24. var testResult = ToBoolean(Call(predicate, thisArg, [kValue, k, O]));
  25. if (testResult) {
  26. return k;
  27. }
  28. k -= 1;
  29. }
  30. return -1;
  31. };