Created
March 29, 2018 18:03
-
-
Save mikeyakymenko/6536b7929233bb2d3cc29e40e40a33b6 to your computer and use it in GitHub Desktop.
some matrix generators (for Oleg)
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
const genMatrix = (args) => { | |
return Array.isArray(args) ? args.map((item) => genMatrix(item)) | |
: Array.apply(null, {length: args}).map(() => false) | |
} | |
const genMatrix2 = (args) => { | |
if (Array.isArray(args)) { | |
return args.map((item) => genMatrix2(item)) | |
} | |
else { | |
return Array.apply(null, {length: args}).map(() => false) | |
} | |
} | |
const genMatrix3 = (x, y) => { | |
return Array.apply(null, {length: x}).map(() => { | |
return Array.apply(null, {length: y}).map(() => false) | |
}) | |
} | |
console.log(genMatrix([3, 2])) | |
console.log(genMatrix2([3, 2])) | |
console.log(genMatrix3(3, 2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment