Generator function that lazily yields matching cells in the quadrille, each as an object of the form { row, col, value }
.
Traversal is row-major (top to bottom, left to right). Returns an IterableIterator
—not an array—so values are produced on demand.
This method is typically used in conjunction withfor...of
orvisit
. Direct use is rare and generally reserved for cases involving array transformations or custom iteration logic.
Examples #
No filter: yield all cells #
q.cells();
Function filter: value-based predicate #
q.cells(({ value }) => value != null);
Use also Quadrille.isFilled(value)
, Quadrille.isEmpty(value)
, or a custom predicate.
Function filter: row and column predicates #
// even rows and columns less than 4
q.cells(({ row, col }) => row % 2 === 0 && col < 4);
Function filter: combined value, row, and col predicates #
q.cells(({ value, row, col }) =>
typeof value === 'string' &&
row % 2 === 0 &&
col < 4
);
Array / Set filter: whitelist of values #
q.cells(['a', 'b', 'c']);
q.cells(new Set([1, 2, 3]));
Yields cells whose value is included.
Advanced: transform or analyze matching cells #
// Extract values from filled cells in the top-left 4×4 block
const values = Array.from(q.cells(({ value, row, col }) =>
Quadrille.isFilled(value) && row < 4 && col < 4
)).map(({ value }) => value);
Use this when:
- you need an array of matching cells,
- you’re chaining with array methods like
map
orreduce
, - or you’re doing offline processing or analysis.
Syntax #
cells()
cells(filter)
Parameters #
Param | Description |
---|---|
filter | Optional filter to select which cells are yielded. It can be:
|