1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:48:10 +00:00

LibJS: Implement Array.prototype.{shift,pop}

This commit is contained in:
Linus Groh 2020-03-28 21:02:45 +00:00 committed by Andreas Kling
parent c5cf740830
commit c209ea1985
5 changed files with 66 additions and 1 deletions

View file

@ -0,0 +1,19 @@
function assert(x) { if (!x) throw 1; }
try {
var a = [1, 2, 3];
var value = a.pop();
assert(value === 3);
assert(a.length === 2);
assert(a[0] === 1);
assert(a[1] === 2);
var a = [];
var value = a.pop();
assert(value === undefined);
assert(a.length === 0);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}

View file

@ -0,0 +1,19 @@
function assert(x) { if (!x) throw 1; }
try {
var a = [1, 2, 3];
var value = a.shift();
assert(value === 1);
assert(a.length === 2);
assert(a[0] === 2);
assert(a[1] === 3);
var a = [];
var value = a.shift();
assert(value === undefined);
assert(a.length === 0);
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);
}