Created
March 29, 2018 18:03
-
-
Save mikeyakymenko/6536b7929233bb2d3cc29e40e40a33b6 to your computer and use it in GitHub Desktop.
Revisions
-
mikeyakymenko created this gist
Mar 29, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,25 @@ 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))