mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +00:00
LibJS: Add Array.prototype.find
This commit is contained in:
parent
fd5f05079d
commit
b0ca174d49
3 changed files with 65 additions and 0 deletions
29
Libraries/LibJS/Tests/Array.prototype.find.js
Normal file
29
Libraries/LibJS/Tests/Array.prototype.find.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
load("test-common.js");
|
||||
|
||||
try {
|
||||
assert(Array.prototype.find.length === 1);
|
||||
|
||||
assertThrowsError(() => {
|
||||
[].find(undefined);
|
||||
}, {
|
||||
error: TypeError,
|
||||
message: "undefined is not a function"
|
||||
});
|
||||
|
||||
var array = ["hello", "friends", 1, 2, false];
|
||||
|
||||
assert(array.find(value => value === "hello") === "hello");
|
||||
assert(array.find((value, index, arr) => index === 1) === "friends");
|
||||
assert(array.find(value => value == "1") === 1);
|
||||
assert(array.find(value => value === 1) === 1);
|
||||
assert(array.find(value => typeof(value) !== "string") === 1);
|
||||
assert(array.find(value => typeof(value) === "boolean") === false);
|
||||
assert(array.find(value => value > 1) === 2);
|
||||
assert(array.find(value => value > 1 && value < 3) === 2);
|
||||
assert(array.find(value => value > 100) === undefined);
|
||||
assert([].find(value => value === 1) === undefined);
|
||||
|
||||
console.log("PASS");
|
||||
} catch (e) {
|
||||
console.log("FAIL: " + e);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue