(arrays, depth = 0)
| 157 | } |
| 158 | |
| 159 | function iterate (arrays, depth = 0) { |
| 160 | // each array can have different sizes |
| 161 | const currentDimensionSize = finalSize[depth] |
| 162 | const result = Array(currentDimensionSize) |
| 163 | if (depth < maxDepth) { |
| 164 | for (let i = 0; i < currentDimensionSize; i++) { |
| 165 | if (index) index[depth] = i |
| 166 | // if there is an offset greater than the current dimension |
| 167 | // pass the array, if the size of the array is 1 pass the first |
| 168 | // element of the array |
| 169 | result[i] = iterate( |
| 170 | arrays.map((array, arrayIndex) => |
| 171 | offsets[arrayIndex] > depth |
| 172 | ? array |
| 173 | : array.length === 1 |
| 174 | ? array[0] |
| 175 | : array[i] |
| 176 | ), |
| 177 | depth + 1 |
| 178 | ) |
| 179 | } |
| 180 | } else { |
| 181 | for (let i = 0; i < currentDimensionSize; i++) { |
| 182 | if (index) index[depth] = i |
| 183 | result[i] = callback( |
| 184 | arrays.map((a) => (a.length === 1 ? a[0] : a[i])), |
| 185 | index ? index.slice() : undefined |
| 186 | ) |
| 187 | } |
| 188 | } |
| 189 | return result |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | /** |
no test coverage detected
searching dependent graphs…