1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 01:07:36 +00:00

LibJS: Add Array.prototype.lastIndexOf

This commit is contained in:
Kesse Jones 2020-04-21 20:17:16 -03:00 committed by Andreas Kling
parent 09138d542d
commit b2305cb67d
3 changed files with 58 additions and 0 deletions

View file

@ -0,0 +1,22 @@
load("test-common.js");
try {
assert(Array.prototype.lastIndexOf.length === 1);
var array = [1, 2, 3, 1, "hello"];
assert(array.lastIndexOf("hello") === 4);
assert(array.lastIndexOf(1) === 3);
assert(array.lastIndexOf(1, -1) === -1);
assert(array.lastIndexOf(1, -2) === 3);
assert(array.lastIndexOf(2) === 1);
assert(array.lastIndexOf(2, -3) === -1);
assert(array.lastIndexOf(2, -4) === 1);
assert([].lastIndexOf('hello') === -1);
assert([].lastIndexOf('hello', 10) === -1);
assert([].lastIndexOf('hello', -10) === -1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}