Skip to content

Instantly share code, notes, and snippets.

@mikeyakymenko
Created March 29, 2018 18:03
Show Gist options
  • Save mikeyakymenko/6536b7929233bb2d3cc29e40e40a33b6 to your computer and use it in GitHub Desktop.
Save mikeyakymenko/6536b7929233bb2d3cc29e40e40a33b6 to your computer and use it in GitHub Desktop.

Revisions

  1. mikeyakymenko created this gist Mar 29, 2018.
    25 changes: 25 additions & 0 deletions someMatrix.js
    Original 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))