visit(callback, value)

Iterates cells in row-major order and calls callback({ row, col, value }) only for cells holding exactly value — matched by identity (===), the same story as strict search and the flood operations. Reading and mutating the grid inside the callback is allowed.

Example

(click to randomize q; every 🐸 cell gets highlighted)

edit, then run

Note

  • The single value filter visits exactly the cells whose value === value.
  • Identity matters for objects: cells filled from one shared color('green') instance are all visited when filtering by that instance, while per-cell Quadrille.factory instances would each need their own filter. Strings, numbers, and emojis compare by value, so '🐸' just works.
  • Functions and Array/Set values can't be single-value filters — they dispatch as predicate and collection filters instead.

Syntax

visit(callback, value)

Parameters

Param Description
callback Function called for each visited cell, receiving an object { row, col, value }. Its return value is ignored
value Any non-function, non-collection value: only cells holding exactly this value (===) are visited
What this page's examples use
p5.quadrille
drawQuadrille createQuadrille cellLength fill visit randomize
p5.js
createCanvas background color

Names the analysis can prove are called, and the line each one is documented on. Local variables and members of an unknown receiver are left out.