Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created December 17, 2019 10:58
Show Gist options
  • Save gkucmierz/1c4c5c06d956f26191ea0cb37e09dd0c to your computer and use it in GitHub Desktop.
Save gkucmierz/1c4c5c06d956f26191ea0cb37e09dd0c to your computer and use it in GitHub Desktop.
const print2dGrid = (grid, pad = 2) => {
const p = ' '.repeat(pad);
console.log(['', ...grid.map(r => r.map(n => (p+n).substr(-pad)).join` `), ''].join`\n`);
};
const square = [
[1, 2, 3, 6, 2, 8, 1],
[4, 8, 2, 4, 3, 1, 9],
[1, 5, 3, 7, 9, 3, 1],
[4, 9, 2, 1, 6, 9, 5],
[7, 6, 8, 4, 7, 2, 6],
[2, 1, 6, 2, 4, 8, 7],
[8, 4, 3, 9, 2, 5, 8]];
print2dGrid(square);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment