Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F9125873
array-iteration-from-last.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
array-iteration-from-last.js
View Options
var
bind
=
require
(
'../internals/function-bind-context'
);
var
IndexedObject
=
require
(
'../internals/indexed-object'
);
var
toObject
=
require
(
'../internals/to-object'
);
var
lengthOfArrayLike
=
require
(
'../internals/length-of-array-like'
);
// `Array.prototype.{ findLast, findLastIndex }` methods implementation
var
createMethod
=
function
(
TYPE
)
{
var
IS_FIND_LAST_INDEX
=
TYPE
==
1
;
return
function
(
$this
,
callbackfn
,
that
)
{
var
O
=
toObject
(
$this
);
var
self
=
IndexedObject
(
O
);
var
boundFunction
=
bind
(
callbackfn
,
that
);
var
index
=
lengthOfArrayLike
(
self
);
var
value
,
result
;
while
(
index
--
>
0
)
{
value
=
self
[
index
];
result
=
boundFunction
(
value
,
index
,
O
);
if
(
result
)
switch
(
TYPE
)
{
case
0
:
return
value
;
// findLast
case
1
:
return
index
;
// findLastIndex
}
}
return
IS_FIND_LAST_INDEX
?
-
1
:
undefined
;
};
};
module
.
exports
=
{
// `Array.prototype.findLast` method
// https://github.com/tc39/proposal-array-find-from-last
findLast
:
createMethod
(
0
),
// `Array.prototype.findLastIndex` method
// https://github.com/tc39/proposal-array-find-from-last
findLastIndex
:
createMethod
(
1
)
};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Jun 21 2025, 9:26 PM (4 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3298720
Attached To
rDWAPPS Web applications
Event Timeline
Log In to Comment