diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md
index 5e8ffb3e9671..cc6b24435432 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/README.md
@@ -30,9 +30,9 @@ limitations under the License.
var nanmaxBy = require( '@stdlib/stats/base/nanmax-by' );
```
-#### nanmaxBy( N, x, stride, clbk\[, thisArg] )
+#### nanmaxBy( N, x, strideX, clbk\[, thisArg] )
-Calculates the maximum value of strided array `x` via a callback function, ignoring `NaN` values.
+Computes the maximum value of a strided array via a callback function, ignoring `NaN` values.
```javascript
function accessor( v ) {
@@ -49,7 +49,7 @@ The function has the following parameters:
- **N**: number of indexed elements.
- **x**: input [`Array`][mdn-array], [`typed array`][mdn-typed-array], or an array-like object (excluding strings and functions).
-- **stride**: index increment.
+- **strideX**: stride length.
- **clbk**: callback function.
- **thisArg**: execution context (_optional_).
@@ -81,19 +81,16 @@ var cnt = context.count;
// returns 10
```
-The `N` and `stride` parameters determine which elements in `x` are accessed at runtime. For example, to access every other element
+The `N` and stride parameters determine which elements in the strided array are accessed at runtime. For example, to access every other element
```javascript
-var floor = require( '@stdlib/math/base/special/floor' );
-
function accessor( v ) {
return v * 2.0;
}
var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0, NaN, NaN ];
-var N = floor( x.length / 2 );
-var v = nanmaxBy( N, x, 2, accessor );
+var v = nanmaxBy( 5, x, 2, accessor );
// returns 8.0
```
@@ -101,7 +98,6 @@ Note that indexing is relative to the first index. To introduce an offset, use [
```javascript
var Float64Array = require( '@stdlib/array/float64' );
-var floor = require( '@stdlib/math/base/special/floor' );
function accessor( v ) {
return v * 2.0;
@@ -112,16 +108,15 @@ var x0 = new Float64Array( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
// Create an offset view...
var x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
-var N = floor( x0.length/2 );
// Access every other element...
-var v = nanmaxBy( N, x1, 2, accessor );
+var v = nanmaxBy( 3, x1, 2, accessor );
// returns -4.0
```
-#### nanmaxBy.ndarray( N, x, stride, offset, clbk\[, thisArg] )
+#### nanmaxBy.ndarray( N, x, strideX, offsetX, clbk\[, thisArg] )
-Calculates the maximum value of strided array `x` via a callback function, ignoring `NaN` values and using alternative indexing semantics.
+Computes the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
```javascript
function accessor( v ) {
@@ -136,9 +131,9 @@ var v = nanmaxBy.ndarray( x.length, x, 1, 0, accessor );
The function has the following additional parameters:
-- **offset**: starting index.
+- **offsetX**: starting index.
-While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying `buffer`, the `offset` parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x`
+While [`typed array`][mdn-typed-array] views mandate a view offset based on the underlying buffer, the offset parameter supports indexing semantics based on a starting index. For example, to access only the last three elements of `x`
```javascript
function accessor( v ) {
@@ -164,6 +159,7 @@ var v = nanmaxBy.ndarray( 3, x, 1, x.length-3, accessor );
- If a provided callback function returns `NaN`, the value is ignored.
- If a provided callback function does not return any value (or equivalently, explicitly returns `undefined`), the value is ignored.
- When possible, prefer using [`dnanmax`][@stdlib/stats/strided/dnanmax], [`snanmax`][@stdlib/stats/strided/snanmax], and/or [`nanmax`][@stdlib/stats/base/nanmax], as, depending on the environment, these interfaces are likely to be significantly more performant.
+- Both functions support array-like objects having getter and setter accessors for array element access (e.g., [`@stdlib/array/base/accessor`][@stdlib/array/base/accessor]).
@@ -176,23 +172,23 @@ var v = nanmaxBy.ndarray( 3, x, 1, x.length-3, accessor );
```javascript
-var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
-var randu = require( '@stdlib/random/base/randu' );
+var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
+var bernoulli = require( '@stdlib/random/base/bernoulli' );
var nanmaxBy = require( '@stdlib/stats/base/nanmax-by' );
-function fill() {
- if ( randu() < 0.2 ) {
+function rand() {
+ if ( bernoulli( 0.8 )< 0.2 ) {
return NaN;
}
- return discreteUniform( -50, 50 );
+ return uniform( -50, 50 );
}
function accessor( v ) {
return v * 2.0;
}
-var x = filledarrayBy( 10, 'float64', fill );
+var x = filledarrayBy( 10, 'float64', rand );
console.log( x );
var v = nanmaxBy( x.length, x, 1, accessor );
@@ -229,6 +225,8 @@ console.log( v );
[mdn-typed-array]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
+[@stdlib/array/base/accessor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/accessor
+
[@stdlib/stats/strided/dnanmax]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/stats/strided/dnanmax
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js
index d7f641b56dfe..bfc13ba47524 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.js
@@ -21,11 +21,13 @@
// MODULES //
var bench = require( '@stdlib/bench' );
-var randu = require( '@stdlib/random/base/randu' );
+var uniform = require( '@stdlib/random/base/uniform' );
+var filledarrayBy = require( '@stdlib/array/filled-by' );
+var bernoulli = require( '@stdlib/random/base/bernoulli' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
-var nanmaxBy = require( './../lib/nanmax_by.js' );
+var nanmaxBy = require( './../lib/main.js' );
// FUNCTIONS //
@@ -41,6 +43,19 @@ function accessor( value ) {
return value * 2.0;
}
+/**
+* Returns a random number.
+*
+* @private
+* @returns {number} random number
+*/
+function rand() {
+ if ( bernoulli( 0.8 ) < 1 ) {
+ return NaN;
+ }
+ return uniform( -50.0, 50.0 );
+}
+
/**
* Create a benchmark function.
*
@@ -49,17 +64,7 @@ function accessor( value ) {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x;
- var i;
-
- x = [];
- for ( i = 0; i < len; i++ ) {
- if ( randu() < 0.2 ) {
- x.push( NaN );
- } else {
- x.push( ( randu()*20.0 ) - 10.0 );
- }
- }
+ var x = filledarrayBy( len, 'generic', rand );
return benchmark;
function benchmark( b ) {
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js
index cb4ba4704442..e4ee26cf6dce 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/benchmark/benchmark.ndarray.js
@@ -21,7 +21,9 @@
// MODULES //
var bench = require( '@stdlib/bench' );
-var randu = require( '@stdlib/random/base/randu' );
+var uniform = require( '@stdlib/random/base/uniform' );
+var filledarrayBy = require( '@stdlib/array/filled-by' );
+var bernoulli = require( '@stdlib/random/base/bernoulli' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pow = require( '@stdlib/math/base/special/pow' );
var pkg = require( './../package.json' ).name;
@@ -41,6 +43,19 @@ function accessor( value ) {
return value * 2.0;
}
+/**
+* Returns a random number.
+*
+* @private
+* @returns {number} random number
+*/
+function rand() {
+ if ( bernoulli( 0.8 ) < 1 ) {
+ return NaN;
+ }
+ return uniform( -50.0, 50.0 );
+}
+
/**
* Create a benchmark function.
*
@@ -49,17 +64,7 @@ function accessor( value ) {
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
- var x;
- var i;
-
- x = [];
- for ( i = 0; i < len; i++ ) {
- if ( randu() < 0.2 ) {
- x.push( NaN );
- } else {
- x.push( ( randu()*20.0 ) - 10.0 );
- }
- }
+ var x = filledarrayBy( len, 'generic', rand );
return benchmark;
function benchmark( b ) {
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt
index 59166ac9c070..d19a14e06764 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/repl.txt
@@ -1,10 +1,10 @@
-{{alias}}( N, x, stride, clbk[, thisArg] )
- Calculates the maximum value of a strided array via a callback function,
+{{alias}}( N, x, strideX, clbk[, thisArg] )
+ Computes the maximum value of strided array via a callback function,
ignoring `NaN` values.
- The `N` and `stride` parameters determine which elements in `x` are accessed
- at runtime.
+ The `N` and stride parameters determine which elements in the strided array
+ are accessed at runtime.
Indexing is relative to the first index. To introduce an offset, use typed
array views.
@@ -34,8 +34,8 @@
Input array/collection. If provided an object, the object must be array-
like (excluding strings and functions).
- stride: integer
- Index increment for `x`.
+ strideX: integer
+ Stride length.
clbk: Function
Callback function.
@@ -56,25 +56,24 @@
> {{alias}}( x.length, x, 1, accessor )
8.0
- // Using `N` and `stride` parameters:
+ // Using `N` and stride parameters:
> x = [ -2.0, 1.0, 3.0, -5.0, 4.0, -1.0, -3.0 ];
- > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
- > {{alias}}( N, x, 2, accessor )
+ > {{alias}}( 3, x, 2, accessor )
8.0
// Using view offsets:
> var x0 = new {{alias:@stdlib/array/float64}}( [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ] );
> var x1 = new {{alias:@stdlib/array/float64}}( x0.buffer, x0.BYTES_PER_ELEMENT*1 );
- > N = {{alias:@stdlib/math/base/special/floor}}( x0.length / 2 );
- > {{alias}}( N, x1, 2, accessor )
+ > {{alias}}( 3, x1, 2, accessor )
-4.0
-{{alias}}.ndarray( N, x, stride, offset, clbk[, thisArg] )
- Calculates the maximum value of a strided array via a callback function,
+
+{{alias}}.ndarray( N, x, strideX, offsetX, clbk[, thisArg] )
+ Computes the maximum value of a strided array via a callback function,
ignoring `NaN` values and using alternative indexing semantics.
While typed array views mandate a view offset based on the underlying
- buffer, the `offset` parameter supports indexing semantics based on a
+ buffer, the offset parameter supports indexing semantics based on a
starting index.
Parameters
@@ -86,11 +85,11 @@
Input array/collection. If provided an object, the object must be array-
like (excluding strings and functions).
- stride: integer
- Index increment for `x`.
+ strideX: integer
+ Stride length.
- offset: integer
- Starting index of `x`.
+ offsetX: integer
+ Starting index.
clbk: Function
Callback function.
@@ -113,8 +112,7 @@
// Using an index offset:
> x = [ 1.0, -2.0, 3.0, -4.0, 5.0, -6.0 ];
- > var N = {{alias:@stdlib/math/base/special/floor}}( x.length / 2 );
- > {{alias}}.ndarray( N, x, 2, 1, accessor )
+ > {{alias}}.ndarray( 3, x, 2, 1, accessor )
-4.0
See Also
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts
index ed14a85bbb5b..106918e08dfe 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/index.d.ts
@@ -20,7 +20,12 @@
///
-import { Collection } from '@stdlib/types/array';
+import { NumericArray, Collection, AccessorArrayLike } from '@stdlib/types/array';
+
+/**
+* Input array.
+*/
+type InputArray = NumericArray | Collection | AccessorArrayLike;
/**
* Returns an accessed value.
@@ -83,7 +88,7 @@ type Callback = Nullary | Unary | Binary | Ternary |
*/
interface Routine {
/**
- * Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values.
+ * Computes the maximum value of a strided array via a callback function, ignoring `NaN` values.
*
* ## Notes
*
@@ -102,7 +107,7 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
- * @param stride - stride length
+ * @param strideX - stride length
* @param clbk - callback
* @param thisArg - execution context
* @returns maximum value
@@ -117,10 +122,10 @@ interface Routine {
* var v = nanmaxBy( x.length, x, 1, accessor );
* // returns 8.0
*/
- ( N: number, x: Collection, stride: number, clbk: Callback, thisArg?: ThisParameterType> ): number;
+ ( N: number, x: InputArray, strideX: number, clbk: Callback, thisArg?: ThisParameterType> ): number;
/**
- * Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
+ * Computes the maximum value of a strided array via a callback function, ignoring `NaN` values and using alternative indexing semantics.
*
* ## Notes
*
@@ -139,8 +144,8 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
- * @param stride - stride length
- * @param offset - starting index
+ * @param strideX - stride length
+ * @param offsetX - starting index
* @param clbk - callback
* @param thisArg - execution context
* @returns maximum value
@@ -155,11 +160,11 @@ interface Routine {
* var v = nanmaxBy.ndarray( x.length, x, 1, 0, accessor );
* // returns 8.0
*/
- ndarray( N: number, x: Collection, stride: number, offset: number, clbk: Callback, thisArg?: ThisParameterType> ): number;
+ ndarray( N: number, x: InputArray, strideX: number, offsetX: number, clbk: Callback, thisArg?: ThisParameterType> ): number;
}
/**
-* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values.
+* Computes the maximum value of a strided array via a callback function, ignoring `NaN` values.
*
* ## Notes
*
@@ -178,7 +183,7 @@ interface Routine {
*
* @param N - number of indexed elements
* @param x - input array
-* @param stride - stride length
+* @param strideX - stride length
* @param clbk - callback
* @param thisArg - execution context
* @returns maximum value
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts
index 171fa67151bf..768e6fa78cf0 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/docs/types/test.ts
@@ -16,6 +16,7 @@
* limitations under the License.
*/
+import AccessorArray = require( '@stdlib/array/base/accessor' );
import nanmaxBy = require( './index' );
const accessor = (): number => {
@@ -30,7 +31,10 @@ const accessor = (): number => {
const x = new Float64Array( 10 );
nanmaxBy( x.length, x, 1, accessor ); // $ExpectType number
+ nanmaxBy( x.length, new AccessorArray( x ), 1, accessor ); // $ExpectType number
+
nanmaxBy( x.length, x, 1, accessor, {} ); // $ExpectType number
+ nanmaxBy( x.length, new AccessorArray( x ), 1, accessor, {} ); // $ExpectType number
}
// The compiler throws an error if the function is provided a first argument which is not a number...
@@ -70,7 +74,7 @@ const accessor = (): number => {
nanmaxBy( x.length, x, undefined, accessor ); // $ExpectError
nanmaxBy( x.length, x, [], accessor ); // $ExpectError
nanmaxBy( x.length, x, {}, accessor ); // $ExpectError
- nanmaxBy( x.length, x, ( x: number, accessor ): number => x, accessor ); // $ExpectError
+ nanmaxBy( x.length, x, ( x: number ): number => x, accessor ); // $ExpectError
}
// The compiler throws an error if the function is provided a fourth argument which is not a function...
@@ -102,7 +106,10 @@ const accessor = (): number => {
const x = new Float64Array( 10 );
nanmaxBy.ndarray( x.length, x, 1, 0, accessor ); // $ExpectType number
+ nanmaxBy.ndarray( x.length, new AccessorArray( x ), 1, 0, accessor ); // $ExpectType number
+
nanmaxBy.ndarray( x.length, x, 1, 0, accessor, {} ); // $ExpectType number
+ nanmaxBy.ndarray( x.length, new AccessorArray( x ), 1, 0, accessor, {} ); // $ExpectType number
}
// The compiler throws an error if the `ndarray` method is provided a first argument which is not a number...
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js
index d10496816b36..b0814b0fad7d 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/examples/index.js
@@ -18,23 +18,23 @@
'use strict';
-var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
-var randu = require( '@stdlib/random/base/randu' );
+var uniform = require( '@stdlib/random/base/uniform' );
var filledarrayBy = require( '@stdlib/array/filled-by' );
+var bernoulli = require( '@stdlib/random/base/bernoulli' );
var nanmaxBy = require( './../lib' );
-function fill() {
- if ( randu() < 0.2 ) {
+function rand() {
+ if ( bernoulli( 0.8 )< 0.2 ) {
return NaN;
}
- return discreteUniform( -50, 50 );
+ return uniform( -50, 50 );
}
function accessor( v ) {
return v * 2.0;
}
-var x = filledarrayBy( 10, 'float64', fill );
+var x = filledarrayBy( 10, 'float64', rand );
console.log( x );
var v = nanmaxBy( x.length, x, 1, accessor );
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js
similarity index 54%
rename from lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js
rename to lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js
index 32c7988df13c..b6e1e8be659f 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/nanmax_by.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/accessors.js
@@ -1,7 +1,7 @@
/**
* @license Apache-2.0
*
-* Copyright (c) 2020 The Stdlib Authors.
+* Copyright (c) 2025 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,60 +27,70 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
// MAIN //
/**
-* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values.
+* Computes the maximum value of a strided array via a callback function, ignoring `NaN` values.
*
* @param {PositiveInteger} N - number of indexed elements
-* @param {Collection} x - input array/collection
-* @param {integer} stride - index increment
+* @param {Object} x - input array object
+* @param {Collection} x.data - input array data
+* @param {Array} x.accessors - array element accessors
+* @param {integer} strideX - stride length
+* @param {NonNegativeInteger} offsetX - starting index
* @param {Callback} clbk - callback
* @param {*} [thisArg] - execution context
* @returns {number} maximum value
*
* @example
-* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ];
+* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
+* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
+*
+* var x = toAccessorArray( [ -2.0, 1.0, 3.0, -5.0, 4.0, NaN, 0.0, -1.0, -3.0 ] );
*
* function accessor( v ) {
* return v * 2.0;
* }
*
-* var v = nanmaxBy( x.length, x, 1, accessor );
+* var v = nanmaxBy( x.length, arraylike2object( x ), 1, 0, accessor );
* // returns 8.0
*/
-function nanmaxBy( N, x, stride, clbk, thisArg ) {
+function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) {
+ var xbuf;
+ var get;
var max;
var ix;
var v;
var i;
+ // Cache reference to array data:
+ xbuf = x.data;
+
+ // Cache a reference to the element accessor:
+ get = x.accessors[0];
+
if ( N <= 0 ) {
return NaN;
}
- if ( N === 1 || stride === 0 ) {
- v = clbk.call( thisArg, x[ 0 ], 0, 0, x );
- if ( v === void 0 ) {
+ if ( N === 1 || strideX === 0 ) {
+ v = clbk.call( thisArg, get( xbuf, offsetX ), 0, offsetX, xbuf );
+ if ( v === void 0 || isnan( v ) ) {
return NaN;
}
return v;
}
- if ( stride < 0 ) {
- ix = (1-N) * stride;
- } else {
- ix = 0;
- }
+ ix = offsetX;
for ( i = 0; i < N; i++ ) {
- max = clbk.call( thisArg, x[ ix ], i, ix, x );
+ max = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf );
if ( max === max && max !== void 0 ) {
break;
}
- ix += stride;
+ ix += strideX;
}
if ( i === N ) {
return NaN;
}
i += 1;
for ( i; i < N; i++ ) {
- ix += stride;
- v = clbk.call( thisArg, x[ ix ], i, ix, x );
+ ix += strideX;
+ v = clbk.call( thisArg, get( xbuf, ix ), i, ix, xbuf );
if ( v === void 0 || isnan( v ) ) {
continue;
}
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/index.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/index.js
index 8995feabfd2d..f35d4e1092d7 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/index.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/index.js
@@ -19,7 +19,7 @@
'use strict';
/**
-* Calculate the maximum value of a strided array via a callback function and ignoring `NaN` values.
+* Compute the maximum value of a strided array via a callback function and ignoring `NaN` values.
*
* @module @stdlib/stats/base/nanmax-by
*
@@ -50,7 +50,14 @@
// MODULES //
+var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
var main = require( './main.js' );
+var ndarray = require( './ndarray.js' );
+
+
+// MAIN //
+
+setReadOnly( main, 'ndarray', ndarray );
// EXPORTS //
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/main.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/main.js
index f1141e54d975..09117b59a4e0 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/main.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/main.js
@@ -20,14 +20,35 @@
// MODULES //
-var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
-var nanmaxBy = require( './nanmax_by.js' );
+var stride2offset = require( '@stdlib/strided/base/stride2offset' );
var ndarray = require( './ndarray.js' );
// MAIN //
-setReadOnly( nanmaxBy, 'ndarray', ndarray );
+/**
+* Computes the maximum value of a strided array via a callback function, ignoring `NaN` values.
+*
+* @param {PositiveInteger} N - number of indexed elements
+* @param {Collection} x - input array/collection
+* @param {integer} strideX - index increment
+* @param {Callback} clbk - callback
+* @param {*} [thisArg] - execution context
+* @returns {number} maximum value
+*
+* @example
+* var x = [ -2.0, 1.0, 3.0, -5.0, 4.0, 0.0, -1.0, -3.0 ];
+*
+* function accessor( v ) {
+* return v * 2.0;
+* }
+*
+* var v = nanmaxBy( x.length, x, 1, accessor );
+* // returns 8.0
+*/
+function nanmaxBy( N, x, strideX, clbk, thisArg ) {
+ return ndarray( N, x, strideX, stride2offset( N, strideX ), clbk, thisArg );
+}
// EXPORTS //
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js
index 1095598082f8..04334929d526 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/lib/ndarray.js
@@ -22,17 +22,19 @@
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
+var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
+var accessors = require( './accessors.js' );
// MAIN //
/**
-* Calculates the maximum value of a strided array via a callback function, ignoring `NaN` values.
+* Computes the maximum value of a strided array via a callback function, ignoring `NaN` values.
*
* @param {PositiveInteger} N - number of indexed elements
* @param {Collection} x - input array/collection
-* @param {integer} stride - index increment
-* @param {NonNegativeInteger} offset - starting index
+* @param {integer} strideX - index increment
+* @param {NonNegativeInteger} offsetX - starting index
* @param {Callback} clbk - callback
* @param {*} [thisArg] - execution context
* @returns {number} maximum value
@@ -47,36 +49,41 @@ var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
* var v = nanmaxBy( x.length, x, 1, 0, accessor );
* // returns 8.0
*/
-function nanmaxBy( N, x, stride, offset, clbk, thisArg ) {
+function nanmaxBy( N, x, strideX, offsetX, clbk, thisArg ) {
var max;
var ix;
+ var o;
var v;
var i;
if ( N <= 0 ) {
return NaN;
}
- if ( N === 1 || stride === 0 ) {
- v = clbk.call( thisArg, x[ 0 ], 0, 0, x );
+ o = arraylike2object( x );
+ if ( o.accessorProtocol ) {
+ return accessors( N, o, strideX, offsetX, clbk, thisArg );
+ }
+ if ( N === 1 || strideX === 0 ) {
+ v = clbk.call( thisArg, x[ offsetX ], 0, offsetX, x );
if ( v === void 0 ) {
return NaN;
}
return v;
}
- ix = offset;
+ ix = offsetX;
for ( i = 0; i < N; i++ ) {
max = clbk.call( thisArg, x[ ix ], i, ix, x );
if ( max === max && max !== void 0 ) {
break;
}
- ix += stride;
+ ix += strideX;
}
if ( i === N ) {
return NaN;
}
i += 1;
for ( i; i < N; i++ ) {
- ix += stride;
+ ix += strideX;
v = clbk.call( thisArg, x[ ix ], i, ix, x );
if ( v === void 0 || isnan( v ) ) {
continue;
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js
index 962b286baf67..75b542f6da57 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.nanmax_by.js
@@ -21,11 +21,11 @@
// MODULES //
var tape = require( 'tape' );
-var floor = require( '@stdlib/math/base/special/floor' );
+var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var Float64Array = require( '@stdlib/array/float64' );
-var nanmaxBy = require( './../lib/nanmax_by.js' );
+var nanmaxBy = require( './../lib/main.js' );
// FUNCTIONS //
@@ -75,11 +75,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba
v = nanmaxBy( x.length, x, 1, accessor );
t.strictEqual( isnan( v ), true, 'returns expected value' );
- x = new Array( 5 ); // sparse array
+ x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array
v = nanmaxBy( x.length, x, 1, accessor );
t.strictEqual( isnan( v ), true, 'returns expected value' );
- x = new Array( 5 ); // sparse array
+ x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array
x[ 2 ] = 1.0;
v = nanmaxBy( x.length, x, 1, accessor );
t.strictEqual( v, 2.0, 'returns expected value' );
@@ -87,6 +87,42 @@ tape( 'the function calculates the maximum value of a strided array via a callba
t.end();
});
+tape( 'the function calculates the maximum value of a strided array via a callback function, ignoring NaN values (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, NaN, 3.0 ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( v, 10.0, 'returns expected value' );
+
+ x = [ -4.0, NaN, -5.0 ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( v, -8.0, 'returns expected value' );
+
+ x = [ -0.0, 0.0, NaN, -0.0 ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
+
+ x = [ NaN ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ x = [ NaN, NaN ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array
+ x[ 2 ] = 1.0;
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( v, 2.0, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) {
var x;
var v;
@@ -102,6 +138,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
t.end();
});
+tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ v = nanmaxBy( 0, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ v = nanmaxBy( -1, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'if provided an `N` parameter equal to `1`, the function returns the first accessed element', function test( t ) {
var x;
var v;
@@ -111,15 +162,30 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first
v = nanmaxBy( 1, x, 1, accessor );
t.strictEqual( v, 2.0, 'returns expected value' );
- x = new Array( 1 ); // sparse array
+ x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array
v = nanmaxBy( 1, x, 1, accessor );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});
+tape( 'if provided an `N` parameter equal to `1`, the function returns the first accessed element (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( v, 2.0, 'returns expected value' );
+
+ x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array
+ v = nanmaxBy( 1, toAccessorArray( x ), 1, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'the function supports a `stride` parameter', function test( t ) {
- var N;
var x;
var v;
@@ -136,15 +202,36 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
NaN
];
- N = floor( x.length / 2 );
- v = nanmaxBy( N, x, 2, accessor );
+ v = nanmaxBy( 5, x, 2, accessor );
+
+ t.strictEqual( v, 8.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [
+ 1.0, // 0
+ 2.0,
+ 2.0, // 1
+ -7.0,
+ -2.0, // 2
+ 3.0,
+ 4.0, // 3
+ 2.0,
+ NaN, // 4
+ NaN
+ ];
+
+ v = nanmaxBy( 5, toAccessorArray( x ), 2, accessor );
t.strictEqual( v, 8.0, 'returns expected value' );
t.end();
});
tape( 'the function supports a negative `stride` parameter', function test( t ) {
- var N;
var x;
var v;
@@ -161,8 +248,30 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
2.0
];
- N = floor( x.length / 2 );
- v = nanmaxBy( N, x, -2, accessor );
+ v = nanmaxBy( 5, x, -2, accessor );
+
+ t.strictEqual( v, 8.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [
+ NaN, // 4
+ NaN,
+ 1.0, // 3
+ 2.0,
+ 2.0, // 2
+ -7.0,
+ -2.0, // 1
+ 3.0,
+ 4.0, // 0
+ 2.0
+ ];
+
+ v = nanmaxBy( 5, toAccessorArray( x ), -2, accessor );
t.strictEqual( v, 8.0, 'returns expected value' );
t.end();
@@ -177,17 +286,32 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f
v = nanmaxBy( x.length, x, 0, accessor );
t.strictEqual( v, 2.0, 'returns expected value' );
- x = new Array( 1 ); // sparse array
+ x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array
v = nanmaxBy( 1, x, 0, accessor );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});
+tape( 'if provided a `stride` parameter equal to `0`, the function returns the first accessed element (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ v = nanmaxBy( x.length, toAccessorArray( x ), 0, accessor );
+ t.strictEqual( v, 2.0, 'returns expected value' );
+
+ x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array
+ v = nanmaxBy( 1, toAccessorArray( x ), 0, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'the function supports view offsets', function test( t ) {
var x0;
var x1;
- var N;
var v;
x0 = new Float64Array([
@@ -205,9 +329,35 @@ tape( 'the function supports view offsets', function test( t ) {
]);
x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
- N = floor(x1.length / 2);
- v = nanmaxBy( N, x1, 2, accessor );
+ v = nanmaxBy( 5, x1, 2, accessor );
+ t.strictEqual( v, 8.0, 'returns expected value' );
+
+ t.end();
+});
+
+tape( 'the function supports view offsets (accessors)', function test( t ) {
+ var x0;
+ var x1;
+ var v;
+
+ x0 = new Float64Array([
+ 2.0,
+ 1.0, // 0
+ 2.0,
+ -2.0, // 1
+ -2.0,
+ 2.0, // 2
+ 3.0,
+ 4.0, // 3
+ 6.0,
+ NaN, // 4
+ NaN
+ ]);
+
+ x1 = new Float64Array( x0.buffer, x0.BYTES_PER_ELEMENT*1 ); // start at 2nd element
+
+ v = nanmaxBy( 5, toAccessorArray( x1 ), 2, accessor );
t.strictEqual( v, 8.0, 'returns expected value' );
t.end();
@@ -231,3 +381,22 @@ tape( 'the function supports providing a callback execution context', function t
return v * 2.0;
}
});
+
+tape( 'the function supports providing a callback execution context (accessors)', function test( t ) {
+ var ctx;
+ var x;
+
+ x = [ 1.0, 2.0, 3.0, NaN, 4.0, 5.0 ];
+ ctx = {
+ 'count': 0
+ };
+ nanmaxBy( x.length, toAccessorArray( x ), 1, accessor, ctx );
+
+ t.strictEqual( ctx.count, x.length, 'returns expected value' );
+ t.end();
+
+ function accessor( v ) {
+ this.count += 1; // eslint-disable-line no-invalid-this
+ return v * 2.0;
+ }
+});
diff --git a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js
index 1979f76e115f..d0567ebca61a 100644
--- a/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js
+++ b/lib/node_modules/@stdlib/stats/base/nanmax-by/test/test.ndarray.js
@@ -21,7 +21,7 @@
// MODULES //
var tape = require( 'tape' );
-var floor = require( '@stdlib/math/base/special/floor' );
+var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var isPositiveZero = require( '@stdlib/math/base/assert/is-positive-zero' );
var nanmaxBy = require( './../lib/ndarray.js' );
@@ -74,11 +74,11 @@ tape( 'the function calculates the maximum value of a strided array via a callba
v = nanmaxBy( x.length, x, 1, 0, accessor );
t.strictEqual( isnan( v ), true, 'returns expected value' );
- x = new Array( 5 ); // sparse array
+ x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array
v = nanmaxBy( x.length, x, 1, 0, accessor );
t.strictEqual( isnan( v ), true, 'returns expected value' );
- x = new Array( 5 ); // sparse array
+ x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array
x[ 2 ] = 1.0;
v = nanmaxBy( x.length, x, 1, 0, accessor );
t.strictEqual( v, 2.0, 'returns expected value' );
@@ -86,6 +86,42 @@ tape( 'the function calculates the maximum value of a strided array via a callba
t.end();
});
+tape( 'the function calculates the maximum value of a strided array via a callback function, ignoring NaN values (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, NaN, 5.0, 0.0, NaN, 3.0 ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( v, 10.0, 'returns expected value' );
+
+ x = [ -4.0, NaN, -5.0 ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( v, -8.0, 'returns expected value' );
+
+ x = [ -0.0, 0.0, NaN, -0.0 ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( isPositiveZero( v ), true, 'returns expected value' );
+
+ x = [ NaN ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ x = [ NaN, NaN ];
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ x = new Array( 5 ); // eslint-disable-line stdlib/no-new-array
+ x[ 2 ] = 1.0;
+ v = nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( v, 2.0, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN`', function test( t ) {
var x;
var v;
@@ -101,6 +137,21 @@ tape( 'if provided an `N` parameter less than or equal to `0`, the function retu
t.end();
});
+tape( 'if provided an `N` parameter less than or equal to `0`, the function returns `NaN` (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ v = nanmaxBy( 0, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ v = nanmaxBy( -1, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'if provided an `N` parameter equal to `1`, the function returns the first accessed element', function test( t ) {
var x;
var v;
@@ -110,15 +161,30 @@ tape( 'if provided an `N` parameter equal to `1`, the function returns the first
v = nanmaxBy( 1, x, 1, 0, accessor );
t.strictEqual( v, 2.0, 'returns expected value' );
- x = new Array( 1 ); // sparse array
+ x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array
v = nanmaxBy( 1, x, 1, 0, accessor );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});
+tape( 'if provided an `N` parameter equal to `1`, the function returns the first accessed element (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ v = nanmaxBy( 1, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( v, 2.0, 'returns expected value' );
+
+ x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array
+ v = nanmaxBy( 1, toAccessorArray( x ), 1, 0, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'the function supports a `stride` parameter', function test( t ) {
- var N;
var x;
var v;
@@ -135,15 +201,36 @@ tape( 'the function supports a `stride` parameter', function test( t ) {
NaN
];
- N = floor( x.length / 2 );
- v = nanmaxBy( N, x, 2, 0, accessor );
+ v = nanmaxBy( 5, x, 2, 0, accessor );
+
+ t.strictEqual( v, 8.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports a `stride` parameter (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [
+ 1.0, // 0
+ 2.0,
+ 2.0, // 1
+ -7.0,
+ -2.0, // 2
+ 3.0,
+ 4.0, // 3
+ 2.0,
+ NaN, // 4
+ NaN
+ ];
+
+ v = nanmaxBy( 5, toAccessorArray( x ), 2, 0, accessor );
t.strictEqual( v, 8.0, 'returns expected value' );
t.end();
});
tape( 'the function supports a negative `stride` parameter', function test( t ) {
- var N;
var x;
var v;
@@ -160,8 +247,30 @@ tape( 'the function supports a negative `stride` parameter', function test( t )
2.0
];
- N = floor( x.length / 2 );
- v = nanmaxBy( N, x, -2, 8, accessor );
+ v = nanmaxBy( 5, x, -2, 8, accessor );
+
+ t.strictEqual( v, 8.0, 'returns expected value' );
+ t.end();
+});
+
+tape( 'the function supports a negative `stride` parameter (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [
+ NaN, // 4
+ NaN,
+ 1.0, // 3
+ 2.0,
+ 2.0, // 2
+ -7.0,
+ -2.0, // 1
+ 3.0,
+ 4.0, // 0
+ 2.0
+ ];
+
+ v = nanmaxBy( 5, toAccessorArray( x ), -2, 8, accessor );
t.strictEqual( v, 8.0, 'returns expected value' );
t.end();
@@ -176,13 +285,29 @@ tape( 'if provided a `stride` parameter equal to `0`, the function returns the f
v = nanmaxBy( x.length, x, 0, 0, accessor );
t.strictEqual( v, 2.0, 'returns expected value' );
- x = new Array( 1 ); // sparse array
+ x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array
v = nanmaxBy( 1, x, 0, 0, accessor );
t.strictEqual( isnan( v ), true, 'returns expected value' );
t.end();
});
+tape( 'if provided a `stride` parameter equal to `0`, the function returns the first accessed element (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [ 1.0, -2.0, -4.0, 5.0, 3.0 ];
+
+ v = nanmaxBy( x.length, toAccessorArray( x ), 0, 0, accessor );
+ t.strictEqual( v, 2.0, 'returns expected value' );
+
+ x = new Array( 1 ); // eslint-disable-line stdlib/no-new-array
+ v = nanmaxBy( 1, toAccessorArray( x ), 0, 0, accessor );
+ t.strictEqual( isnan( v ), true, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'the function supports an offset parameter', function test( t ) {
var x;
var v;
@@ -204,6 +329,27 @@ tape( 'the function supports an offset parameter', function test( t ) {
t.end();
});
+tape( 'the function supports an offset parameter (accessors)', function test( t ) {
+ var x;
+ var v;
+
+ x = [
+ 1.0,
+ -2.0, // 0
+ 3.0,
+ 4.0, // 1
+ 5.0,
+ -6.0, // 2
+ NaN,
+ NaN // 3
+ ];
+
+ v = nanmaxBy( 4, toAccessorArray( x ), 2, 1, accessor );
+ t.strictEqual( v, 8.0, 'returns expected value' );
+
+ t.end();
+});
+
tape( 'the function supports providing a callback execution context', function test( t ) {
var ctx;
var x;
@@ -222,3 +368,22 @@ tape( 'the function supports providing a callback execution context', function t
return v * 2.0;
}
});
+
+tape( 'the function supports providing a callback execution context (accessors)', function test( t ) {
+ var ctx;
+ var x;
+
+ x = [ 1.0, 2.0, 3.0, NaN, 4.0, 5.0 ];
+ ctx = {
+ 'count': 0
+ };
+ nanmaxBy( x.length, toAccessorArray( x ), 1, 0, accessor, ctx );
+
+ t.strictEqual( ctx.count, x.length, 'returns expected value' );
+ t.end();
+
+ function accessor( v ) {
+ this.count += 1; // eslint-disable-line no-invalid-this
+ return v * 2.0;
+ }
+});