@@ -93,17 +93,15 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed })
9393 }
9494 )
9595
96- let callback
9796 let callbackCase
9897
9998 if ( typed . isTypedFunction ( multiCallback ) ) {
10099 const firstIndex = newSize . map ( ( ) => 0 )
101100 callbackCase = _getTypedCallbackCase ( multiCallback , firstValues , firstIndex , Arrays )
102- callback = _getLimitedCallback ( callbackCase )
103101 } else {
104102 callbackCase = _getCallbackCase ( multiCallback , numberOfArrays )
105- callback = _getLimitedCallback ( callbackCase )
106103 }
104+ const callback = _getLimitedCallback ( callbackCase )
107105
108106 if ( callbackCase < 2 ) {
109107 return mapMultiple ( Arrays , callback )
@@ -119,7 +117,7 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed })
119117
120118 const broadcastedArraysCallback = ( x , idx ) =>
121119 callback (
122- [ x , ...broadcastedArrays . slice ( 1 ) . map ( Array => _get ( Array , idx ) ) ] ,
120+ [ x , ...broadcastedArrays . slice ( 1 ) . map ( array => _get ( array , idx ) ) ] ,
123121 idx )
124122
125123 if ( firstArrayIsMatrix ) {
@@ -173,13 +171,12 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed })
173171 const sizes = Collections . map ( ( collection ) =>
174172 collection . isMatrix ? collection . size ( ) : arraySize ( collection )
175173 )
176- // this should be changed for the specific function when impelemented
177174 const finalSize = broadcastSizes ( ...sizes )
178175 // the offset means for each initial array, how much smaller is it than the final size
179176 const offsets = sizes . map ( ( size ) => finalSize . length - size . length )
180- // make the iteration algorithm
181177 const maxDepth = finalSize . length - 1
182- const index = [ ]
178+ const callbackUsesIndex = callback . length > 1
179+ const index = callbackUsesIndex ? [ ] : null
183180 const resultsArray = iterate ( Arrays , 0 )
184181 if ( firstCollectionIsMatrix ) {
185182 const returnMatrix = firstCollection . create ( )
@@ -189,15 +186,14 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed })
189186 } else {
190187 return resultsArray
191188 }
192- // will create references to the arrays depth, depending on the offset.
193189
194190 function iterate ( arrays , depth = 0 ) {
195- // each array can have differt sizes
191+ // each array can have different sizes
196192 const N = finalSize [ depth ]
197193 const result = Array ( N )
198194 if ( depth < maxDepth ) {
199195 for ( let i = 0 ; i < N ; i ++ ) {
200- index [ depth ] = i
196+ if ( index ) index [ depth ] = i
201197 // if there is an offset greather than the current dimension
202198 // pass the array, if the size of the array is 1 pass the first
203199 // element of the array
@@ -214,10 +210,10 @@ export const createMap = /* #__PURE__ */ factory(name, dependencies, ({ typed })
214210 }
215211 } else {
216212 for ( let i = 0 ; i < N ; i ++ ) {
217- index [ depth ] = i
213+ if ( index ) index [ depth ] = i
218214 result [ i ] = callback (
219215 arrays . map ( ( a ) => ( a . length === 1 ? a [ 0 ] : a [ i ] ) ) ,
220- index . slice ( )
216+ index ? index . slice ( ) : undefined
221217 )
222218 }
223219 }
0 commit comments