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 gridfunctioncreateGrid(rows, cols) {
let grid = newArray(rows).fill(null).map(() =>newArray(cols).fill('.'));
return grid;
}
// Function to get the midpoint nodes of the gridfunctiongetMidpointNodes(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 gridconst grid = createGrid(rows, cols);
console.log(grid);
// Get the midpoint nodes of the gridconst midpointNodes = getMidpointNodes(grid);
console.log(midpointNodes);