Skip to content

Instantly share code, notes, and snippets.

@hjzheng
Last active August 17, 2020 06:09
Show Gist options
  • Save hjzheng/f45540d10426e1ea0dcc740be3ed63cb to your computer and use it in GitHub Desktop.
Save hjzheng/f45540d10426e1ea0dcc740be3ed63cb to your computer and use it in GitHub Desktop.
usefull array from
// Sequence generator function (commonly referred to as "range", e.g. Clojure, PHP etc)
const range = (start, stop, step) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
// create 2d array
const create2DArray = (m, n, initVal) => Array.from(new Array(m), () => new Array(n).fill(initVal))
// create 3d array
const create3DArray = (m, n, d, initVal) => Array.from(new Array(m), () => Array.from(new Array(n), () => new Array(d).fill(initVal)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment