Skip to content

Commit 5bfda32

Browse files
committed
fix: implementation
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 78846cb commit 5bfda32

File tree

5 files changed

+66
-88
lines changed

5 files changed

+66
-88
lines changed

lib/node_modules/@stdlib/stats/base/nanmin-by/lib/accessors.js

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,34 @@ var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
2727
// MAIN //
2828

2929
/**
30-
* Calculates the minimum value of a strided array via a callback function, ignoring `NaN` values.
30+
* Computes the minimum value of a strided array via a callback function, ignoring `NaN` values.
3131
*
3232
* @param {PositiveInteger} N - number of indexed elements
33-
* @param {Collection} x - input array/collection
34-
* @param {integer} strideX - index increment
33+
* @param {Object} x - input array object
34+
* @param {Collection} x.data - input array data
35+
* @param {Array<Function>} x.accessors - array element accessors
36+
* @param {integer} strideX - stride length
3537
* @param {NonNegativeInteger} offsetX - starting index
3638
* @param {Callback} clbk - callback
3739
* @param {*} [thisArg] - execution context
3840
* @returns {number} minimum value
3941
*
4042
* @example
41-
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
43+
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
44+
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
45+
*
46+
* var x = toAccessorArray( [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ] );
4247
*
4348
* function accessor( v ) {
4449
* return v * 2.0;
4550
* }
4651
*
47-
* var v = nanminBy( x.length, x, 1, 0, accessor );
52+
* var v = nanminBy( x.length, arraylike2object( x ), 1, 0, accessor );
4853
* // returns -10.0
4954
*/
5055
function nanminBy( N, x, strideX, offsetX, clbk, thisArg ) {
5156
var xbuf;
5257
var get;
53-
var max;
5458
var min;
5559
var ix;
5660
var v;
@@ -61,35 +65,36 @@ function nanminBy( N, x, strideX, offsetX, clbk, thisArg ) {
6165

6266
// Cache a reference to the element accessor:
6367
get = x.accessors[0];
68+
6469
if ( N <= 0 ) {
65-
return NaN;
70+
return NaN;
6671
}
6772
if ( N === 1 || strideX === 0 ) {
68-
v = clbk.call( thisArg, get( xbuf, 0 ), 0, 0, x );
69-
if ( v === void 0 || isnan( v ) ) {
70-
return NaN;
71-
}
72-
return v;
73+
v = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, x );
74+
if ( v === void 0 || isnan( v ) ) {
75+
return NaN;
76+
}
77+
return v;
7378
}
7479
ix = offsetX;
7580
for ( i = 0; i < N; i++ ) {
76-
min = clbk.call( thisArg, get( xbuf, ix ), i, ix, x );
77-
if ( min === min && min !== void 0 ) {
78-
break;
79-
}
80-
ix += strideX;
81+
min = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf );
82+
if ( min === min && min !== void 0 ) {
83+
break;
84+
}
85+
ix += strideX;
8186
}
8287
if ( i === N ) {
83-
return NaN;
88+
return NaN;
8489
}
8590
i += 1;
86-
for( i ; i < N ; i++ ) {
91+
for ( i; i < N; i++ ) {
8792
ix += strideX;
88-
v = clbk.call( thisArg, get( xbuf, ix ), i, ix, x );
89-
if ( v === void 0 || isnan( v ) ) {
90-
continue;
91-
}
92-
if( v < min || ( v === min && isNegativeZero( v ) ) ) {
93+
v = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf );
94+
if ( v === void 0 || isnan( v ) ) {
95+
continue;
96+
}
97+
if ( v < min || ( v === min && isNegativeZero( v ) ) ) {
9398
min = v;
9499
}
95100
}
@@ -99,4 +104,4 @@ function nanminBy( N, x, strideX, offsetX, clbk, thisArg ) {
99104

100105
// EXPORTS //
101106

102-
module.exports = nanminBy;
107+
module.exports = nanminBy;

lib/node_modules/@stdlib/stats/base/nanmin-by/lib/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Calculate the minimum value of a strided array via a callback function and ignoring `NaN` values.
22+
* Compute the minimum value of a strided array via a callback function and ignoring `NaN` values.
2323
*
2424
* @module @stdlib/stats/base/nanmin-by
2525
*
@@ -50,7 +50,14 @@
5050

5151
// MODULES //
5252

53+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
5354
var main = require( './main.js' );
55+
var ndarray = require( './ndarray.js' );
56+
57+
58+
// MAIN //
59+
60+
setReadOnly( main, 'ndarray', ndarray );
5461

5562

5663
// EXPORTS //

lib/node_modules/@stdlib/stats/base/nanmin-by/lib/main.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,35 @@
2020

2121
// MODULES //
2222

23-
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
24-
var nanminBy = require( './nanmin_by.js' );
23+
var stride2offset = require( '@stdlib/strided/base/stride2offset' );
2524
var ndarray = require( './ndarray.js' );
2625

2726

2827
// MAIN //
2928

30-
setReadOnly( nanminBy, 'ndarray', ndarray );
29+
/**
30+
* Computes the minimum value of a strided array via a callback function, ignoring `NaN` values.
31+
*
32+
* @param {PositiveInteger} N - number of indexed elements
33+
* @param {Collection} x - input array/collection
34+
* @param {integer} strideX - index increment
35+
* @param {Callback} clbk - callback
36+
* @param {*} [thisArg] - execution context
37+
* @returns {number} minimum value
38+
*
39+
* @example
40+
* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
41+
*
42+
* function accessor( v ) {
43+
* return v * 2.0;
44+
* }
45+
*
46+
* var v = nanminBy( x.length, x, 1, accessor );
47+
* // returns -10.0
48+
*/
49+
function nanminBy( N, x, strideX, clbk, thisArg ) {
50+
return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg );
51+
}
3152

3253

3354
// EXPORTS //

lib/node_modules/@stdlib/stats/base/nanmin-by/lib/nanmin_by.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

lib/node_modules/@stdlib/stats/base/nanmin-by/lib/ndarray.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2025 The Stdlib Authors.
4+
* Copyright (c) 2020 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ var accessors = require( './accessors.js' );
2929
// MAIN //
3030

3131
/**
32-
* Calculates the minimum value of a strided array via a callback function, ignoring `NaN` values.
32+
* Computes the minimum value of a strided array via a callback function, ignoring `NaN` values.
3333
*
3434
* @param {PositiveInteger} N - number of indexed elements
3535
* @param {Collection} x - input array/collection
@@ -60,11 +60,11 @@ function nanminBy( N, x, strideX, offsetX, clbk, thisArg ) {
6060
return NaN;
6161
}
6262
o = arraylike2object( x );
63-
if( o.accessorProtocol ) {
63+
if ( o.accessorProtocol ) {
6464
return accessors( N, o, strideX, offsetX, clbk, thisArg );
6565
}
6666
if ( N === 1 || strideX === 0 ) {
67-
v = clbk.call( thisArg, x[ 0 ], 0, 0, x );
67+
v = clbk.call( thisArg, x[ offsetX ], 0, offsetX, x );
6868
if ( v === void 0 ) {
6969
return NaN;
7070
}

0 commit comments

Comments
 (0)