1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:47:44 +00:00

LibJS: Add Array.prototype.findIndex

This commit is contained in:
Kesse Jones 2020-04-26 13:22:09 -03:00 committed by Andreas Kling
parent bf9926743a
commit 36c00e8078
3 changed files with 65 additions and 0 deletions

View file

@ -0,0 +1,29 @@
load("test-common.js");
try {
assert(Array.prototype.findIndex.length === 1);
assertThrowsError(() => {
[].findIndex(undefined);
}, {
error: TypeError,
message: "undefined is not a function"
});
var array = ["hello", "friends", 1, 2, false];
assert(array.findIndex(value => value === "hello") === 0);
assert(array.findIndex((value, index, arr) => index === 1) === 1);
assert(array.findIndex(value => value == "1") === 2);
assert(array.findIndex(value => value === 1) === 2);
assert(array.findIndex(value => typeof(value) !== "string") === 2);
assert(array.findIndex(value => typeof(value) === "boolean") === 4);
assert(array.findIndex(value => value > 1) === 3);
assert(array.findIndex(value => value > 1 && value < 3) === 3);
assert(array.findIndex(value => value > 100) === -1);
assert([].findIndex(value => value === 1) === -1);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}