mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 22:27:35 +00:00
Spreadsheet: Add find, findIndex, indexOf, & has to CommonRange
This commit is contained in:
parent
87c818c571
commit
75a02300ba
2 changed files with 107 additions and 16 deletions
|
@ -141,6 +141,49 @@ class CommonRange {
|
|||
return found;
|
||||
}
|
||||
|
||||
findIndex(matcher) {
|
||||
let i = 0;
|
||||
let found = false;
|
||||
this.forEach(cell => {
|
||||
if (matcher(cell, i)) {
|
||||
found = true;
|
||||
return Break;
|
||||
}
|
||||
++i;
|
||||
});
|
||||
return found ? i : -1;
|
||||
}
|
||||
|
||||
find(matcher) {
|
||||
let value = null;
|
||||
let i = 0;
|
||||
this.forEach(cell => {
|
||||
if (matcher(cell, i)) {
|
||||
value = cell;
|
||||
return Break;
|
||||
}
|
||||
++i;
|
||||
});
|
||||
return value;
|
||||
}
|
||||
|
||||
indexOf(name) {
|
||||
let i = 0;
|
||||
let found = false;
|
||||
this.forEach(cell => {
|
||||
if (cell.name === name) {
|
||||
found = true;
|
||||
return Break;
|
||||
}
|
||||
++i;
|
||||
});
|
||||
return found ? i : -1;
|
||||
}
|
||||
|
||||
has(name) {
|
||||
return this.indexOf(name) !== -1;
|
||||
}
|
||||
|
||||
toArray() {
|
||||
const cells = [];
|
||||
this.forEach(val => cells.push(val));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue