1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:57:35 +00:00

Spreadsheet: Add Range(s).at(ix)

This commit is contained in:
u9g 2022-02-27 13:39:17 -05:00 committed by Ali Mohammad Pur
parent 629eed3a4c
commit d047f26a74
2 changed files with 37 additions and 0 deletions

View file

@ -147,6 +147,18 @@ class Ranges {
}
}
at(wantedIx) {
let ix = 0;
let found = null;
this.forEach(cell => {
if (ix++ === wantedIx) {
found = cell;
return Break;
}
});
return found;
}
union(other, direction = "right") {
if (direction === "left") {
if (other instanceof Ranges) return Ranges.from(...other.ranges, ...this.ranges);
@ -213,6 +225,18 @@ class Range {
}
}
at(wantedIx) {
let ix = 0;
let found = null;
this.forEach(cell => {
if (ix++ === wantedIx) {
found = cell;
return Break;
}
});
return found;
}
union(other) {
if (other instanceof Ranges) return other.union(this, "left");