Skip to content

Instantly share code, notes, and snippets.

@LeoAJ
Last active November 28, 2016 17:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LeoAJ/5c086c45255d6bf9009c90826678a00b to your computer and use it in GitHub Desktop.
Save LeoAJ/5c086c45255d6bf9009c90826678a00b to your computer and use it in GitHub Desktop.
Generate `n` dimensional matrix
/**
* n = 3, offset = 1
* [
* [1, 2, 3],
* [4, 5, 6],
* [7, 8, 9]
* ]
*/
const createMatrix = (n, offset = 0) => Array.from(
{ length: n }, (v1, i1) => Array.from(
{ length: n }, (v2, i2) => i1 * n + i2 + offset
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment