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.
some matrix generators (for Oleg)
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