Last active
August 17, 2020 06:09
-
-
Save hjzheng/f45540d10426e1ea0dcc740be3ed63cb to your computer and use it in GitHub Desktop.
usefull array from
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
// 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