This commit is contained in:
nim-ka
2022-11-17 00:57:31 +00:00
parent 26120e2818
commit c42480ef0b
6 changed files with 133 additions and 12 deletions

View File

@@ -80,6 +80,8 @@ Grid = class Grid {
}
findIndex(func) {
func = typeof func == "function" ? func : (e) => e == func
for (let y = 0; y < this.height; y++) {
for (let x = 0; x < this.width; x++) {
let pt = new Point(x, y)
@@ -97,8 +99,11 @@ Grid = class Grid {
}
findAllIndices(func) {
func = typeof func == "function" ? func : (e) => e == func
let points = [].pt
this.forEach((e, pt, grid) => func(e, pt, grid) ? points.push(pt) : 0)
return points
}
@@ -106,6 +111,10 @@ Grid = class Grid {
return this.findAllIndices(func).map((pt) => this.get(pt))
}
count(func) {
return this.findAllIndices(func).length
}
indexOf(val) {
return this.findIndex((e) => e == val)
}