(recShape, recIndices)
| 92 | * @returns {Matrix} |
| 93 | */ |
| 94 | const generateRecursively = (recShape, recIndices) => { |
| 95 | if (recShape.length === 1) { |
| 96 | return Array(recShape[0]) |
| 97 | .fill(null) |
| 98 | .map((cellValue, cellIndex) => fill([...recIndices, cellIndex])); |
| 99 | } |
| 100 | const m = []; |
| 101 | for (let i = 0; i < recShape[0]; i += 1) { |
| 102 | m.push(generateRecursively(recShape.slice(1), [...recIndices, i])); |
| 103 | } |
| 104 | return m; |
| 105 | }; |
| 106 | |
| 107 | return generateRecursively(mShape, []); |
| 108 | }; |