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.

This method is typically used in conjunction with for...of or visit. 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: 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 or reduce,
  • or you’re doing offline processing or analysis.

Syntax #

cells()
cells(filter)

Parameters #

ParamDescription
filterOptional filter to select which cells are yielded. It can be:
  • a value collection (Array or Set)
  • a predicate function (value => boolean)
  • an object with optional value, row, and/or col predicate functions
If omitted, all cells are returned