make a 10x10 manhattan grid with midpoint nodes in javascript

index.tsx
// Create a 10x10 Manhattan grid with midpoint nodes in JavaScript

// Function to create a 10x10 Manhattan grid
function createGrid(rows, cols) {
    let grid = new Array(rows).fill(null).map(() => new Array(cols).fill('.'));
    return grid;
}

// Function to get the midpoint nodes of the grid
function getMidpointNodes(grid) {
    let midpointNodes = [];
    for (let i = 0; i < grid.length; i += 2) {
        for (let j = 0; j < grid[i].length; j += 2) {
            midpointNodes.push({ row: i, col: j });
        }
    }
    return midpointNodes;
}

const rows = 10;
const cols = 10;

// Create a 10x10 Manhattan grid
const grid = createGrid(rows, cols);
console.log(grid);

// Get the midpoint nodes of the grid
const midpointNodes = getMidpointNodes(grid);
console.log(midpointNodes);
794 chars
30 lines

related categories

gistlibby LogSnag