Skip to content

Commit a0a285d

Browse files
authored
fix: update callback invocation logic to ensure correct arguments
Signed-off-by: Athan <[email protected]>
1 parent 1a280b1 commit a0a285d

File tree

1 file changed

+14
-3
lines changed
  • lib/node_modules/@stdlib/stats/array/max-by/lib

1 file changed

+14
-3
lines changed

lib/node_modules/@stdlib/stats/array/max-by/lib/main.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,21 @@ function maxBy( x, clbk, thisArg ) {
7070
if ( !isFunction( clbk ) ) {
7171
throw new TypeError( format( 'invalid argument. Callback function must be a function. Value: `%s`.', clbk ) );
7272
}
73-
if (arguments.length > 2) {
74-
return strided( x.length, x, 1, 0, clbk, thisArg );
73+
return strided( x.length, x, 1, 0, wrapper );
74+
75+
/**
76+
* Invokes a provided callback.
77+
*
78+
* @private
79+
* @param {number} value - current element
80+
* @param {NonNegativeInteger} aidx - current array index
81+
* @param {NonNegativeInteger} sidx - current strided index
82+
* @param {NumericArray} arr - input array
83+
* @returns {number} callback return value
84+
*/
85+
function wrapper( value, aidx, sidx, arr ) {
86+
return clbk.call( thisArg, value, aidx, arr );
7587
}
76-
return strided( x.length, x, 1, 0, clbk );
7788
}
7889

7990

0 commit comments

Comments
 (0)