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

Spreadsheet: Add Range(s).toArray()

This commit is contained in:
u9g 2022-03-02 18:30:14 -05:00 committed by Ali Mohammad Pur
parent 6302ca0043
commit 93115ee044
3 changed files with 40 additions and 9 deletions

View file

@ -171,6 +171,12 @@ class Ranges {
}
}
toArray() {
const cells = [];
this.forEach(val => cells.push(val));
return cells;
}
toString() {
return `Ranges.from(${this.ranges.map(r => r.toString()).join(", ")})`;
}
@ -263,6 +269,12 @@ class Range {
}
}
toArray() {
const cells = [];
this.forEach(val => cells.push(val));
return cells;
}
toString() {
const endingRow = this.endingRow ?? "";
return `R\`${this.startingColumnName}${this.startingRow}:${this.endingColumnName}${endingRow}:${this.columnStep}:${this.rowStep}\``;
@ -340,12 +352,8 @@ function numericResolve(cells) {
}
function resolve(cells) {
let values = [];
if (cells instanceof Range || cells instanceof Ranges)
cells.forEach(cell => values.push(cell.value()));
else values = cells;
return values;
const isRange = cells instanceof Range || cells instanceof Ranges;
return isRange ? cells.toArray().map(cell => cell.value()) : cells;
}
// Statistics