Published
Edited
Dec 7, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
stats = playToWin(boards, draws)
Insert cell
// it works and it’s yuck
playToWin = (boards, draws, bingo = false) => {
let winning = ({board: null, row: null});
draws.forEach(
draw => {
if (bingo) return;
boards.forEach(
(board, b) => {
if (bingo) return;
["rows", "columns"].forEach(
(direction) => board[direction].forEach(
(strip, s) => {
if (bingo) return;
strip.delete(draw);
if (bingo = (strip.size === 0)) {
const remaining = sum(boards[b]);
winning = ({
boards,
board: boards[b],
boardNumber: b,
direction,
strip: s,
draw,
remaining,
score: draw * remaining
});
return;
} // bingo
} // strip
) // strips
) // rows, columns
} // board
) // boards
} // draw
) // draws
return winning;
}
Insert cell
sum = (board, sum = 0) => {
board.rows.forEach(
row => row.forEach(
r => sum += r
)
)
return sum;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more