Last active
April 9, 2022 04:16
-
-
Save JeremyIglehart/b14a71bfb8f01cec76aff41d0485b925 to your computer and use it in GitHub Desktop.
Visualizing Directional Exploration of a Matrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Visualizing Directional Exploration of a Matrix | |
A little homework for myself. I find it difficult at times to visualize a | |
matrix when it's represented as an array. Specifically when I'm setting up | |
some array of directions for BFS style matrix searching - I always have to | |
think very about the array I setup for exploring different directions. | |
So, I wrote this - to prove it out for myself and run it in a browser console. | |
Thanks Chroms for your awesome console.log display :) | |
*/ | |
let directions = [[0,0], [0, 1], [1, 1], [1,0], [1, -1], [0, -1], [-1,-1], [-1, 0], [-1, 1]]; | |
let testDirection = (x, y) => { | |
let grid = [[0,0,0], [0,0,0], [0,0,0]]; | |
let i = 1; | |
let j = 1; | |
grid[i+x][j+y] = 1; | |
console.log(grid); | |
} | |
for (const [index, [x,y]] of directions.entries()) { | |
console.log(`Index: ${index}, x: ${x} y: ${y}`); | |
testDirection(x, y); | |
} |
Author
JeremyIglehart
commented
Apr 9, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment