Skip to content

Instantly share code, notes, and snippets.

@JeremyIglehart
Last active April 9, 2022 04:16
Show Gist options
  • Save JeremyIglehart/b14a71bfb8f01cec76aff41d0485b925 to your computer and use it in GitHub Desktop.
Save JeremyIglehart/b14a71bfb8f01cec76aff41d0485b925 to your computer and use it in GitHub Desktop.
Visualizing Directional Exploration of a Matrix
/*
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);
}
@JeremyIglehart
Copy link
Author

Screen Shot 2022-04-08 at 21 15 26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment