mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:17:44 +00:00
LibJS: Implement 'Relative Indexing Method' proposal (.at())
Still stage 3, but already implemented in major engines and unlikely to change - there isn't much to change here anyway. :^) See: - https://github.com/tc39/proposal-relative-indexing-method - https://tc39.es/proposal-relative-indexing-method/ - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/at
This commit is contained in:
parent
9769542bc2
commit
2d8362cceb
10 changed files with 155 additions and 10 deletions
|
@ -0,0 +1,15 @@
|
|||
test("basic functionality", () => {
|
||||
expect(Array.prototype.at).toHaveLength(1);
|
||||
|
||||
const array = ["a", "b", "c"];
|
||||
expect(array.at(0)).toBe("a");
|
||||
expect(array.at(1)).toBe("b");
|
||||
expect(array.at(2)).toBe("c");
|
||||
expect(array.at(3)).toBeUndefined();
|
||||
expect(array.at(Infinity)).toBeUndefined();
|
||||
expect(array.at(-1)).toBe("c");
|
||||
expect(array.at(-2)).toBe("b");
|
||||
expect(array.at(-3)).toBe("a");
|
||||
expect(array.at(-4)).toBeUndefined();
|
||||
expect(array.at(-Infinity)).toBeUndefined();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue