MCPcopy Create free account
hub / github.com/TheCSir/TerminalStart / createGrid

Function createGrid

src/utils/gameOfLifeUtils.ts:1–10  ·  view source on GitHub ↗
(rows: number, cols: number, probability: number = 0.3)

Source from the content-addressed store, hash-verified

1export const createGrid = (rows: number, cols: number, probability: number = 0.3): boolean[][] => {
2 const grid: boolean[][] = [];
3 for (let y = 0; y < rows; y++) {
4 grid[y] = [];
5 for (let x = 0; x < cols; x++) {
6 grid[y][x] = Math.random() < probability;
7 }
8 }
9 return grid;
10};
11
12export const countNeighbors = (grid: boolean[][], x: number, y: number, rows: number, cols: number): number => {
13 let count = 0;

Callers 2

randomizeFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected