cells(filter?)
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.
ℹ️
Examples
No filter: yield all cells
q.cells();
Function filter: test value only
q.cells(value => value != null);
Use Quadrille.isFilled
, Quadrille.isEmpty
, or a custom predicate.
Array / Set filter: whitelist of values
q.cells(['a', 'b', 'c']);
q.cells(new Set([1, 2, 3]));
Yields cells whose value is included.
Object filter: combine value, row, and col predicates
q.cells({
value: v => typeof v === 'string',
row: r => r % 2 === 0,
col: c => c < 4
});
Each predicate is optional. All must match if provided.
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: Quadrille.isFilled,
row: r => r < 4,
col: c => c < 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:
|