Created
June 23, 2020 18:56
-
-
Save rustam-swe/3e7c38feed6190a36146946b43cc7f67 to your computer and use it in GitHub Desktop.
Makes multidimensional array from an existing array
This file contains 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
function makeMultidimensionalArray(inputArray, arraysCount = 20, arrayLength = 1) { | |
return [...Array(arraysCount)] // Create an array with number of elements (default = 20) | |
.map((item, index) => { | |
return Array(arrayLength).fill(inputArray[index]) // Make an inner array with the length of "index" (default = 1) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment