MCPcopy Create free account
hub / github.com/josdejong/mathjs / iterate

Function iterate

src/function/matrix/map.js:159–190  ·  view source on GitHub ↗
(arrays, depth = 0)

Source from the content-addressed store, hash-verified

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 /**

Callers 1

mapMultipleFunction · 0.70

Calls 2

callbackFunction · 0.70
mapMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…