Skip to content

Commit 9da485e

Browse files
committed
refactor: allow arrays of any dtype
--- 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: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - 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: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed ---
1 parent 61b019f commit 9da485e

File tree

5 files changed

+20
-47
lines changed

5 files changed

+20
-47
lines changed

lib/node_modules/@stdlib/stats/array/min-by/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
Parameters
1919
----------
20-
x: Array<number>|TypedArray
20+
x: Array|TypedArray
2121
Input array.
2222

2323
clbk: Function

lib/node_modules/@stdlib/stats/array/min-by/docs/types/index.d.ts

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

2121
/// <reference types="@stdlib/types"/>
2222

23-
import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
23+
import { Collection, AccessorArrayLike } from '@stdlib/types/array';
2424

2525
/**
2626
* Input array.
2727
*/
28-
type InputArray = NumericArray | Collection<number> | AccessorArrayLike<number>;
28+
type InputArray<T> = Collection<T> | AccessorArrayLike<T>;
2929

3030
/**
3131
* Returns an accessed value.
@@ -89,7 +89,7 @@ type Callback<T, U, ThisArg> = Nullary<ThisArg> | Unary<T, ThisArg> | Binary<T,
8989
* var v = minBy( x, accessor );
9090
* // returns -10.0
9191
*/
92-
declare function minBy<T = number, U extends InputArray = InputArray, ThisArg = unknown>( x: U, clbk: Callback<T, U, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, ThisArg>> ): number;
92+
declare function minBy<T = unknown, U extends InputArray<T> = InputArray<T>, ThisArg = unknown>( x: U, clbk: Callback<T, U, ThisArg>, thisArg?: ThisParameterType<Callback<T, U, ThisArg>> ): number;
9393

9494

9595
// EXPORTS //

lib/node_modules/@stdlib/stats/array/min-by/docs/types/test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,14 @@
1919
import AccessorArray = require( '@stdlib/array/base/accessor' );
2020
import minBy = require( './index' );
2121

22-
const accessor = (): number => {
22+
/**
23+
* Accessor function.
24+
*
25+
* @returns accessed value
26+
*/
27+
function accessor(): number {
2328
return 5.0;
24-
};
29+
}
2530

2631

2732
// TESTS //
@@ -40,7 +45,6 @@ const accessor = (): number => {
4045
// The compiler throws an error if the function is provided a first argument which is not a numeric array...
4146
{
4247
minBy( 10, accessor ); // $ExpectError
43-
minBy( '10', accessor ); // $ExpectError
4448
minBy( true, accessor ); // $ExpectError
4549
minBy( false, accessor ); // $ExpectError
4650
minBy( null, accessor ); // $ExpectError

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,31 +21,20 @@
2121
// MODULES //
2222

2323
var isCollection = require( '@stdlib/assert/is-collection' );
24-
var dtypes = require( '@stdlib/array/dtypes' );
25-
var dtype = require( '@stdlib/array/dtype' );
26-
var contains = require( '@stdlib/array/base/assert/contains' );
27-
var join = require( '@stdlib/array/base/join' );
24+
var isFunction = require( '@stdlib/assert/is-function' );
2825
var strided = require( '@stdlib/stats/base/min-by' ).ndarray;
2926
var format = require( '@stdlib/string/format' );
30-
var isFunction = require( '@stdlib/assert/is-function' );
31-
32-
33-
// VARIABLES //
34-
35-
var IDTYPES = dtypes( 'real_and_generic' );
36-
var GENERIC_DTYPE = 'generic';
3727

3828

3929
// MAIN //
4030

4131
/**
4232
* Computes the minimum value of an array via a callback function.
4333
*
44-
* @param {NumericArray} x - input array
34+
* @param {Collection} x - input array
4535
* @param {Callback} clbk - callback
4636
* @param {*} [thisArg] - execution context
4737
* @throws {TypeError} first argument must be an array-like object
48-
* @throws {TypeError} first argument must have a supported data type
4938
* @throws {TypeError} second argument must be a function
5039
* @returns {number} minimum value
5140
*
@@ -60,14 +49,9 @@ var GENERIC_DTYPE = 'generic';
6049
* // returns -10.0
6150
*/
6251
function minBy( x, clbk, thisArg ) {
63-
var dt;
6452
if ( !isCollection( x ) ) {
6553
throw new TypeError( format( 'invalid argument. First argument must be an array-like object. Value: `%s`.', x ) );
6654
}
67-
dt = dtype( x ) || GENERIC_DTYPE;
68-
if ( !contains( IDTYPES, dt ) ) {
69-
throw new TypeError( format( 'invalid argument. First argument must have one of the following data types: "%s". Data type: `%s`.', join( IDTYPES, '", "' ), dt ) );
70-
}
7155
if ( !isFunction( clbk ) ) {
7256
throw new TypeError( format( 'invalid argument. Second argument must be a function. Value: `%s`.', clbk ) );
7357
}

lib/node_modules/@stdlib/stats/array/min-by/test/test.js

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,18 @@ var tape = require( 'tape' );
2424
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2525
var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
2626
var isNegativeZero = require( '@stdlib/math/base/assert/is-negative-zero' );
27-
var BooleanArray = require( '@stdlib/array/bool' );
28-
var Complex128Array = require( '@stdlib/array/complex128' );
2927
var minBy = require( './../lib/main.js' );
3028

3129

3230
// FUNCTIONS //
3331

32+
/**
33+
* Accessor function.
34+
*
35+
* @private
36+
* @param {number} v - value
37+
* @returns {(number|void)} result
38+
*/
3439
function accessor( v ) {
3540
if ( v === void 0 ) {
3641
return;
@@ -79,26 +84,6 @@ tape( 'the function throws an error if provided a first argument which is not an
7984
}
8085
});
8186

82-
tape( 'the function throws an error if provided a first argument which has an unsupported data type', function test( t ) {
83-
var values;
84-
var i;
85-
86-
values = [
87-
new BooleanArray( 4 ),
88-
new Complex128Array( 4 )
89-
];
90-
for ( i = 0; i < values.length; i++ ) {
91-
t.throws( badValue( values[ i ] ), TypeError, 'throws an error when provided ' + values[ i ] );
92-
}
93-
t.end();
94-
95-
function badValue( value ) {
96-
return function badValue() {
97-
minBy( value, accessor );
98-
};
99-
}
100-
});
101-
10287
tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) {
10388
var values;
10489
var i;

0 commit comments

Comments
 (0)