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

Spreadsheet: Add CommonRange#unique()

This commit is contained in:
u9g 2022-03-05 19:56:46 -05:00 committed by Ali Mohammad Pur
parent b9d44eb022
commit c8803afe3e
2 changed files with 28 additions and 0 deletions

View file

@ -197,6 +197,19 @@ class CommonRange {
});
return new SplitRange(cells);
}
unique() {
const cells = [];
const values = new Set();
this.forEach(cell => {
const value = cell.value();
if (!values.has(value)) {
values.add(value);
cells.push(cell);
}
});
return new SplitRange(cells);
}
}
class SplitRange extends CommonRange {