Searching in a grid
Finding a cell
Use the findCell function to find the cell that first matches the specified search function.
import {createGridFromArray2D} from "gridl/core";
import {findCell} from "gridl/search";
const grid = createGridFromArray2D([
[1, 1, 1, 4],
[5, 6, 2, 8],
[0, 2, 3, 4],
]);
findCell((v) => v > 2, grid); // => 4
Finding a position
Use the findPosition function to find the position that first matches the specified search function.
import {findPosition} from "gridl/search";
const grid = createGridFromArray2D([
[1, 1, 1, 4],
[5, 6, "test", 8],
[1, "test", 3, 4],
]);
findPosition((v) => v > 2, grid); // => {x: 3, y: 0}
findPosition((v) => typeof v === "string", grid); // => {x: 2, y: 1}