From a9583975c577c5d2ee5b9ac083246e5bbeee1510 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 24 Sep 2024 21:29:30 -0400 Subject: [PATCH] chore: clean-up implementation --- .../array/base/cuany-by-right/README.md | 152 +++++++ .../benchmark/benchmark.assign.length.js | 89 ++-- .../benchmark/{benckmark.js => benchmark.js} | 50 +- ...enckmark.length.js => benchmark.length.js} | 18 +- .../array/base/cuany-by-right/docs/repl.txt | 59 ++- .../base/cuany-by-right/docs/types/index.d.ts | 157 ++++++- .../base/cuany-by-right/docs/types/test.ts | 198 ++++++-- .../base/cuany-by-right/examples/index.js | 18 +- .../array/base/cuany-by-right/lib/assign.js | 294 ++++-------- .../array/base/cuany-by-right/lib/index.js | 30 +- .../array/base/cuany-by-right/lib/main.js | 22 +- .../array/base/cuany-by-right/package.json | 130 +++--- .../base/cuany-by-right/test/test.assign.js | 427 +++++++----------- .../array/base/cuany-by-right/test/test.js | 2 - .../base/cuany-by-right/test/test.main.js | 185 +++----- 15 files changed, 945 insertions(+), 886 deletions(-) create mode 100644 lib/node_modules/@stdlib/array/base/cuany-by-right/README.md rename lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/{benckmark.js => benchmark.js} (58%) rename lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/{benckmark.length.js => benchmark.length.js} (81%) diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/README.md b/lib/node_modules/@stdlib/array/base/cuany-by-right/README.md new file mode 100644 index 00000000000..301eb769744 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/README.md @@ -0,0 +1,152 @@ + + +# cuanyByRight + +> Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. + +
+ +## Usage + +```javascript +var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' ); +``` + +#### cuanyByRight( x, predicate\[, thisArg] ) + +Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var x = [ 0, 0, 0, 1, 0 ]; + +var y = cuanyByRight( x, isPositive ); +// returns [ false, true, true, true, true ] +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: input array. + +To set the `predicate` function execution context, provide a `thisArg`. + +```javascript +function isPositive( value ) { + this.count += 1; + return ( value > 0 ); +} + +var x = [ 0, 1, 0, 0, 0 ]; + +var context = { + 'count': 0 +}; + +var out = cuanyByRight( x, isPositive, context ); +// returns [ false, false, false, true, true ] + +var cnt = context.count; +// returns 4 +``` + +#### cuanyByRight.assign( x, out, stride, offset, predicate\[, thisArg] ) + +Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left, and assigns results to a provided output array. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var x = [ 0, 1, 0, 0, 0 ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cuanyByRight.assign( x, y, 2, 0, isPositive ); +// returns [ false, null, false, null, false, null, true, null, true, null ] + +var bool = ( out === y ); +// returns true +``` + +The function supports the following parameters: + +- **x**: input array. +- **out**: output array. +- **stride**: output array stride. +- **offset**: output array offset. +- **predicate**: test function. + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.1 ); +console.log( x ); + +var out = cuanyByRight( x, isPositive ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.assign.length.js index b2d0a5e3fbe..7116da4d52c 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.assign.length.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.assign.length.js @@ -23,6 +23,7 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; var filled = require( '@stdlib/array/base/filled' ); var pkg = require( './../package.json' ).name; var cuanyByRight = require( './../lib' ); @@ -38,48 +39,38 @@ var cuanyByRight = require( './../lib' ); * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filled( 1.5, len ); - return benchmark; + var x = filled( 1.5, len ); + return benchmark; - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var y; - var v; - var i; + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var y; + var v; + var i; - y = filled( false, len ); + y = filled( false, len ); - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = cuanyByRight.assign( x, y, 1, 0, isPositive ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); - } + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyByRight.assign( x, y, 1, 0, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } } -/** -* Predicate function to test if a value is positive. -* -* @private -* @param {number} value - input value -* @returns {boolean} boolean indicating whether the value is positive -*/ -function isPositive( value ) { - return ( value > 0 ); -} // MAIN // @@ -89,20 +80,20 @@ function isPositive( value ) { * @private */ function main() { - var len; - var min; - var max; - var f; - var i; + var len; + var min; + var max; + var f; + var i; - min = 1; // 10^min - max = 6; // 10^max + min = 1; // 10^min + max = 6; // 10^max - for ( i = min; i <= max; i++ ) { - len = pow( 10, i ); - f = createBenchmark( len ); - bench( pkg + ':assign:len=' + len, f ); - } + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':assign:len='+len, f ); + } } main(); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benckmark.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.js similarity index 58% rename from lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benckmark.js rename to lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.js index cf1954b48ec..e6515d804b0 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benckmark.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.js @@ -22,6 +22,7 @@ var bench = require( '@stdlib/bench' ); var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; var cuanyByRight = require( './../lib' ); @@ -29,34 +30,23 @@ var cuanyByRight = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { - var x; - var i; - var v; - - x = [ 0, 1, 0, 0, 0 ]; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - v = cuanyByRight( x, isPositive ); - if ( typeof v !== 'object' ) { - b.fail( 'should return an array' ); - } - } - b.toc(); - if ( !isArray( v ) ) { - b.fail( 'should return an array' ); - } - b.pass( 'benchmark finished' ); - b.end(); + var x; + var i; + var v; + + x = [ 1, 1, 0, 0, 0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyByRight( x, isPositiveInteger ); + if ( typeof v !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( v ) ) { + b.fail( 'should return an array' ); + } + b.pass( 'benchmark finished' ); + b.end(); }); - -/** -* Predicate function to test if a value is positive. -* -* @private -* @param {number} value - input value -* @returns {boolean} boolean indicating whether the value is positive -*/ -function isPositive( value ) { - return ( value > 0 ); -} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benckmark.length.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.length.js similarity index 81% rename from lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benckmark.length.js rename to lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.length.js index 65b3c776547..a3fe131c396 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benckmark.length.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/benchmark/benchmark.length.js @@ -23,10 +23,10 @@ var bench = require( '@stdlib/bench' ); var pow = require( '@stdlib/math/base/special/pow' ); var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; var filled = require( '@stdlib/array/base/filled' ); var pkg = require( './../package.json' ).name; -// var cuanyByRight = require( './../lib' ); -import cuanyByRight from '@stdlib/array/base/cuany-by-right/lib/main'; +var cuanyByRight = require( './../lib' ); // FUNCTIONS // @@ -39,7 +39,7 @@ import cuanyByRight from '@stdlib/array/base/cuany-by-right/lib/main'; * @returns {Function} benchmark function */ function createBenchmark( len ) { - var x = filled( 1.5, len ); + var x = filled( 0, len ); return benchmark; /** @@ -54,7 +54,7 @@ function createBenchmark( len ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = cuanyByRight( x, isPositive ); + v = cuanyByRight( x, isPositiveInteger ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } @@ -68,16 +68,6 @@ function createBenchmark( len ) { } } -/** -* Predicate function to test if a value is positive. -* -* @private -* @param {number} value - input value -* @returns {boolean} boolean indicating whether the value is positive -*/ -function isPositive( value ) { - return ( value > 0 ); -} // MAIN // diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/repl.txt index 3b2afc96fb2..3fec5fd54a1 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/repl.txt @@ -1,12 +1,25 @@ -cuanyByRight( x ) - Cumulatively tests whether at least one element in a provided array is - truthy, starting from the rightmost element. +{{alias}}( x, predicate[, thisArg] ) + Cumulatively tests whether at least one array element in a provided array + passes a test implemented by a predicate function, while iterating from + right-to-left. + + The predicate function is provided three arguments: + + - value: current array element. + - index: current array element index. + - arr: the input array. Parameters ---------- x: ArrayLikeObject Input array. + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + Returns ------- out: Array @@ -14,20 +27,29 @@ cuanyByRight( x ) Examples -------- - > var x = [ false, false, true, false, false ]; - > var y = cuanyByRight( x ) - [ false, false, true, true, true ] + > function isPositive( v ) { return ( v > 0 ); }; + > var x = [ 1, 1, 0, 0, 0 ]; + > var y = {{alias}}( x, isPositive ) + [ false, false, false, true, true ] -cuanyByRight.assign( x, y, stride, offset ) - Cumulatively tests whether at least one element in an array is truthy, starting from the rightmost element, and assigns results to provided output array. +{{alias}}.assign( x, out, stride, offset, predicate[, thisArg] ) + Cumulatively tests whether at least one array element in a provided array + passes a test implemented by a predicate function, while iterating from + right-to-left, and assigns the results to the provided output array. + + The predicate function is provided three arguments: + + - value: current array element. + - index: current array element index. + - arr: the input array. Parameters ---------- x: ArrayLikeObject Input array. - y: ArrayLikeObject + out: ArrayLikeObject Output array. stride: integer @@ -36,17 +58,26 @@ cuanyByRight.assign( x, y, stride, offset ) offset: integer Output array offset. + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + Returns ------- - y: ArrayLikeObject + out: ArrayLikeObject Output array. Examples -------- - > var x = [ false, false, true, false, false ]; - > var y = [ false, null, false, null, false, null, false, null, false ]; - > var result = cuanyByRight.assign( x, y, 2, 0 ) - [ false, null, true, null, true, null, true, null, true ] + > function isPositive( v ) { return ( v > 0 ); }; + > var x = [ 1, 1, 0, 0 ]; + > var out = [ false, null, false, null, false, null, false, null ]; + > var arr = {{alias}}.assign( x, out, 2, 0, isPositive ) + [ false, null, false, null, false, null, true, null ] + > var bool = ( arr === out ) + true See Also -------- diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/index.d.ts index f784035128b..33524ad8710 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/index.d.ts @@ -16,73 +16,182 @@ * limitations under the License. */ -// TypeScript Version: 4.1 - /// -import { Collection, AccessorArrayLike } from '@stdlib/types/array'; +import { Collection, AccessorArrayLike, TypedArray, BooleanArray } from '@stdlib/types/array'; + +/** +* Checks whether an element in a collection passes a test. +* +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @param collection - input collection +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Ternary = ( this: U, value: T, index: number, collection: Collection ) => boolean; + +/** +* Checks whether an element in a collection passes a test. +* +* @param value - collection value +* @param index - collection index +* @param collection - input collection +* @returns boolean indicating whether an element in a collection passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; /** * Interface describing `cuanyByRight`. */ -interface CuAnyByRight { +interface CuanyByRight { /** - * Cumulatively tests whether at least one element in a provided array is truthy (from right to left). + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. * * @param x - input array + * @param predicate - test function + * @param thisArg - execution context * @returns output array * * @example - * var x = [ false, false , true, false , false ]; + * function isPositive( v ) { + * return v > 0; + * } + * var x = [ 0, 1, 1, 0, 0 ]; * - * var y = cuanyByRight( x ); - * // returns [ true, true, true, false, false ]; + * var y = cuanyByRight( x, isPositive ); + * // returns [ false, false, true, true, true ] */ - ( x: Collection | AccessorArrayLike ): Array; + ( x: Collection | AccessorArrayLike, predicate: Predicate, thisArg?: ThisParameterType> ): Array; /** - * Cumulatively tests whether at least one element in an array is truthy (from right to left) and assigns the results to a provided output array. + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. * * @param x - input array * @param y - output array * @param stride - output array stride * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return v > 0; + * } + * var x = [ 1, 1, 0, 0, 0 ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); + * // returns [ false, null, false, null, false, null, true, null, true, null ] + */ + assign( x: Collection | AccessorArrayLike, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * + * @param x - input array + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * var BooleanArray = require( '@stdlib/array/bool' ); + * + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] ); + * + * var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); + * // returns + * + * var v = arr.get( 6 ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; + + /** + * Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array. + * + * @param x - input array + * @param out - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - test function + * @param thisArg - execution context * @returns output array * * @example - * var x = [ false, false, true, false, false ]; + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 0, 0, 0, 1, 0 ]; * var y = [ false, null, false, null, false, null, false, null, false, null ]; * - * var arr = cuanyByRight.assign( x, y, 2, 0 ); - * // returns [ true, null, true, null, true, null, false, null, false, null ]; + * var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); + * // returns [ false, null, false, null, false, null, true, null, true, null ] */ - assign | AccessorArrayLike>( x: Collection | AccessorArrayLike, y: U, stride: number, offset: number ): U; + assign( x: Collection | AccessorArrayLike, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; } /** -* Cumulatively tests whether at least one element in a provided array is truthy (from right to left). +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. * * @param x - input array +* @param predicate - test function +* @param thisArg - execution context * @returns output array * * @example -* var x = [ false, false, true, false, false ]; +* function isPositive( v ) { +* return v > 0; +* } +* var x = [ 1, 1, 0, 0, 0 ]; * -* var result = cuanyByRight( x ); -* // returns [ true, true, true, false, false ] +* var result = cuanyByRight( x, isPositive ); +* // returns [ false, false, false, true, true ] * * @example -* var x = [ false, false, true, false, false ]; +* function isPositive( v ) { +* return v > 0; +* } +* var x = [ 0, 1, 1, 0, 0 ]; * var y = [ false, null, false, null, false, null, false, null, false, null ]; * -* var arr = cuanyByRight.assign( x, y, 2, 0 ); -* // returns [ true, null, true, null, true, null, false, null, false, null ] +* var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] */ -declare var cuanyByRight: CuAnyByRight; +declare var cuanyByRight: CuanyByRight; // EXPORTS // export = cuanyByRight; - - diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/test.ts index 8d4bc500786..8a012f9a9f6 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/test.ts +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/docs/types/test.ts @@ -17,73 +17,159 @@ */ -import * as cuanyByRight from './index'; +import cuanyByRight = require( './index' ); + +/** +* Tests whether a value is positive. +* +* @param value - input value +* @returns boolean indicating whether an element is positive +*/ +function isPositive( value: number ): boolean { + return ( value > 0 ); +} // TESTS // // The function returns an array... { - cuanyByRight( [ false, false, true, false, false ] ); // $ExpectType boolean[] - cuanyByRight( [ false, false, true, false, false ] ); // $ExpectType boolean[] + cuanyByRight( [ 1, 2, 3 ], isPositive ); // $ExpectType boolean[] + cuanyByRight( new Float64Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Float32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Int32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Int16Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Int8Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Uint32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Uint16Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Uint8Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyByRight( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + + cuanyByRight( [ 1, 2, 3 ], isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Float64Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Float32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Int32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Int16Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Int8Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Uint32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Uint16Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Uint8Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyByRight( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] } -// The compiler throws an error if the function is provided a first argument which is not an array-like object... +// The compiler throws an error if the function is provided a first argument which is not like a function.. { - cuanyByRight( [1] ); // $ExpectError - cuanyByRight( [true] ); // $ExpectError - cuanyByRight( [ false ] ); // $ExpectError - cuanyByRight( [] ); // Provide an empty array as the argument instead of null. - cuanyByRight( [] ); // Provide an empty array as the argument instead of null. - cuanyByRight( [] ); // Provide an empty array as the argument instead of an object. -} + const x = [ 1, 2, 3, 4 ]; + cuanyByRight( x, null ); // $ExpectError + cuanyByRight( x, {} ); // $ExpectError + cuanyByRight( x, [] ); // $ExpectError + cuanyByRight( x, '' ); // $ExpectError + cuanyByRight( x, undefined ); // $ExpectError + cuanyByRight( x, null, {} ); // $ExpectError + cuanyByRight( x, {}, {} ); // $ExpectError + cuanyByRight( x, [], {} ); // $ExpectError + cuanyByRight( x, '', {} ); // $ExpectError + cuanyByRight( x, undefined, {} ); // $ExpectError + +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cuanyByRight(); // $ExpectError + cuanyByRight( [] ); // $ExpectError + cuanyByRight( [ 1, 2 ], isPositive, {}, '' ); // $ExpectError +} // Attached to the main export is an `assign` method which returns a collection... { - const x = [ false, false, true, false, false ]; + const x = [ 0, 0, 0, 1, 0 ]; const y = [ false, null, false, null, false, null, false, null, false, null ]; - cuanyByRight.assign( x, y, 2, 0 ); // $ExpectType (boolean | null)[] + cuanyByRight.assign( x, y, 2, 0, isPositive ); // $ExpectType (boolean | null)[] + cuanyByRight.assign( x, y, 2, 0, isPositive, {} ); // $ExpectType (boolean | null)[] + cuanyByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array + cuanyByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array + cuanyByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array + cuanyByRight.assign( x, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array + cuanyByRight.assign( x, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array + cuanyByRight.assign( x, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array + cuanyByRight.assign( x, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array + cuanyByRight.assign( x, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array + cuanyByRight.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray + + cuanyByRight.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[] + cuanyByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array + cuanyByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array + cuanyByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array + cuanyByRight.assign( x, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array + cuanyByRight.assign( x, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array + cuanyByRight.assign( x, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array + cuanyByRight.assign( x, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array + cuanyByRight.assign( x, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array + cuanyByRight.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8ClampedArray } // The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... { const x = [ false, false, true, false, false ]; - cuanyByRight.assign( [1], x, 2, 0 ); // $ExpectError - cuanyByRight.assign( [true], x, 2, 0 ); // $ExpectError - cuanyByRight.assign( [false], x, 2, 0 ); // $ExpectError - cuanyByRight.assign( [], x, 2, 0 ); // $ExpectError - cuanyByRight.assign( [], x, 2, 0 ); // $ExpectError - cuanyByRight.assign( [], x, 2, 0 ); // $ExpectError + cuanyByRight.assign( 1, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( true, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( false, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( null, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( void 0, x, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( {}, x, 2, 0, isPositive ); // $ExpectError + + cuanyByRight.assign( 1, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( true, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( false, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( null, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( void 0, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( {}, x, 2, 0, isPositive, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object... { const x = [ false, false, true, false, false ]; - cuanyByRight.assign( x, [1], 2, 0 ); // $ExpectError - cuanyByRight.assign( x, [true], 2, 0 ); // $ExpectError - cuanyByRight.assign( x, [false], 2, 0 ); // $ExpectError - cuanyByRight.assign( x, [], 2, 0 ); // $ExpectError - cuanyByRight.assign( x,[], 2, 0 ); // $ExpectError - cuanyByRight.assign( x, [], 2, 0 ); // $ExpectError + cuanyByRight.assign( x, 1, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, true, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, false, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, null, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, void 0, 2, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, {}, 2, 0, isPositive ); // $ExpectError + + cuanyByRight.assign( x, 1, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, true, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, false, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, null, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, void 0, 2, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, {}, 2, 0, isPositive, {} ); // $ExpectError } + // The compiler throws an error if the `assign` method is provided a third argument which is not a number... { const x = [ false, false, true, false, false ]; const y = [ false, null, false, null, false, null, false, null, false, null ]; - cuanyByRight.assign( x, y , 1, 0 ); // $ExpectError - cuanyByRight.assign( x, y , 2, 0 ); // $ExpectError - cuanyByRight.assign( x, y , 0, 0 ); // $ExpectError - cuanyByRight.assign( x, y , 0, 0 ); // $ExpectError - cuanyByRight.assign( x, y , 0, 0 ); // $ExpectError - cuanyByRight.assign( x, y , 0, 0 ); // $ExpectError - cuanyByRight.assign( x, y , 0, 0 ); // $ExpectError + cuanyByRight.assign( x, y , '1', 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , true, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , false, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , null, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , void 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , {}, 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y , [], 0, isPositive ); // $ExpectError + + cuanyByRight.assign( x, y , '1', 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , true, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , false, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , null, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , void 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , {}, 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y , [], 0, isPositive, {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... @@ -91,20 +177,44 @@ import * as cuanyByRight from './index'; const x = [ false, false, true, false, false ]; const y = [ false, null, false, null, false, null, false, null, false, null ]; - cuanyByRight.assign( x, y, 1, 1 ); // $ExpectError - cuanyByRight.assign( x, y, 1, 1 ); // $ExpectError - cuanyByRight.assign( x, y, 1, 0 ); // $ExpectError - cuanyByRight.assign( x, y, 1, 0 ); // Provide a valid number as the fourth argument instead of null. - cuanyByRight.assign( x, y, 1, 0 ); // Provide a valid number as the fourth argument instead of undefined. - cuanyByRight.assign( x, y, 1, 0 ); // $ExpectError - cuanyByRight.assign( x, y, 1, 0 ); // $ExpectError + cuanyByRight.assign( x, y, 1, '1', isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, true, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, false, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, null, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, void 0, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, {}, isPositive ); // $ExpectError + cuanyByRight.assign( x, y, 1, [], isPositive ); // $ExpectError + + cuanyByRight.assign( x, y, 1, '1', isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, true, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, false, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, null, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, void 0, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, {}, isPositive, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, [], isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not like a function... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyByRight.assign( x, y, 1, 2, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, 2, void 0 ); // $ExpectError + cuanyByRight.assign( x, y, 1, 1, [] ); // $ExpectError + cuanyByRight.assign( x, y, 1, 1, '' ); // $ExpectError + + cuanyByRight.assign( x, y, 1, 2, {}, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, 2, void 0, {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, 1, [], {} ); // $ExpectError + cuanyByRight.assign( x, y, 1, 1, '', {} ); // $ExpectError } // The compiler throws an error if the `assign` method is provided an unsupported number of arguments... { - cuanyByRight.assign([], [], 0, 0); // $ExpectError - cuanyByRight.assign( [], [], 0, 0 ); // $ExpectError - cuanyByRight.assign( [], [], 0, 0 ); // $ExpectError - cuanyByRight.assign( [], [], 2, 0 ); // $ExpectError - cuanyByRight.assign( [], [], 1, 1 ); // $ExpectError + cuanyByRight.assign(); // $ExpectError + cuanyByRight.assign( [] ); // $ExpectError + cuanyByRight.assign( [], [] ); // $ExpectError + cuanyByRight.assign( [], [], 2 ); // $ExpectError + cuanyByRight.assign( [], [], 1, 1, isPositive, [], {} ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/examples/index.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/examples/index.js index f2fc50dbbc8..07c56c9cd10 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/examples/index.js @@ -19,24 +19,16 @@ 'use strict'; var bernoulli = require( '@stdlib/random/array/bernoulli' ); - var cuanyByRight = require( './../lib' ); +function isPositive( value ) { + return ( value > 0 ); +} + // Create an array of random values: var x = bernoulli( 10, 0.1 ); console.log( x ); -// Cumulatively determine whether values are truthy from right-to-left: +// Cumulatively test whether at least one array element passes a test, while iterating from right-to-left: var out = cuanyByRight( x, isPositive ); console.log( out ); - -/** -* Predicate function to test if a value is positive. -* -* @private -* @param {number} value - input value -* @returns {boolean} boolean indicating whether the value is positive -*/ -function isPositive( value ) { - return ( value > 0 ); -} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/assign.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/assign.js index 3c0db30ca48..446859239d7 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/assign.js @@ -20,266 +20,152 @@ // MODULES // -var isComplex128Array = require( '@stdlib/array/base/assert/is-complex128array' ); -var isComplex64Array = require( '@stdlib/array/base/assert/is-complex64array' ); -var isBooleanArray = require( '@stdlib/array/base/assert/is-booleanarray' ); var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -var reinterpret128 = require( '@stdlib/strided/base/reinterpret-complex128' ); -var reinterpret64 = require( '@stdlib/strided/base/reinterpret-complex64' ); -var reinterpretBoolean = require( '@stdlib/strided/base/reinterpret-boolean' ); + // FUNCTIONS // /** -* Cumulatively tests whether at least one element in an indexed array is truthy, iterating from right to left. +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the provided output array. * * @private * @param {Collection} x - input array * @param {Collection} y - output array * @param {integer} stride - output array stride * @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} thisArg - execution context * @returns {Collection} output array * * @example -* var x = [ false, false, true, false, false ]; -* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 1, 0, 0, 0 ]; * -* var out = indexed( x, y, 2, 0 ); -* // returns [ false, null, false, null, true, null, true, null, true, null ] +* var out = [ false, false, false, false, false ]; +* var y = indexed( x, out, 1, 0, isPositive ); +* // returns [ false, false, false, true, true ] */ -function indexed( x, y, stride, offset ) { - var flg; - var io; - var i; - - flg = false; - io = offset + ((x.length - 1) * stride); // Added parentheses to ensure correct order of operations - for ( i = x.length - 1; i >= 0; i-- ) { - if ( flg === false && x[ i ] ) { - flg = true; - } - y[ io ] = flg; - io -= stride; - } - return y; +function indexed( x, y, stride, offset, predicate, thisArg ) { + var flg; + var io; + var i; + + flg = false; + io = offset; + for ( i = x.length - 1; i >= 0; i-- ) { + if ( !flg && predicate.call( thisArg, x[ i ], i, x ) ) { + flg = true; + } + y[ io ] = flg; + io += stride; + } + return y; } /** -* Cumulatively tests whether at least one element in a provided accessor array is truthy, iterating from right to left. +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the accessor output array. * * @private * @param {Object} x - input array object * @param {Object} y - output array object * @param {integer} stride - output array stride * @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} thisArg - execution context * @returns {Collection} output array * * @example -* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -* -* var x = toAccessorArray( [ false, false, true, false, false ] ); -* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); -* -* var arr = accessors( arraylike2object( x ), arraylike2object( y ), 2, 0 ); -* -* var v = y.get( 0 ); -* // returns false -* -* v = y.get( 2 ); -* // returns false +* function isPositive( value ) { +* return ( value > 0 ); +* } * -* v = y.get( 4 ); -* // returns true -* -* v = y.get( 6 ); -* // returns true -* -* v = y.get( 8 ); -* // returns true -*/ -function accessors( x, y, stride, offset ) { - var xdata; - var ydata; - var xget; - var yset; - var flg; - var io; - var i; - - xdata = x.data; - ydata = y.data; - - xget = x.accessors[ 0 ]; - yset = y.accessors[ 1 ]; - - flg = false; - io = offset + ((xdata.length - 1) * stride); // Added parentheses to ensure correct order of operations - for ( i = xdata.length - 1; i >= 0; i-- ) { - if ( flg === false && xget( xdata, i ) ) { - flg = true; - } - yset( ydata, io, flg ); - io -= stride; - } - return ydata; -} - -/** -* Cumulatively tests whether at least one element in a provided complex number array is truthy, iterating from right to left. -* -* @private -* @param {Collection} x - array containing interleaved real and imaginary components -* @param {Object} y - output array object -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array offset -* @returns {Collection} output array -* -* @example -* var Float64Array = require( '@stdlib/array/float64' ); * var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); * var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); * -* var x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0 ] ); -* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); -* -* var arr = complex( x, arraylike2object( y ), 2, 0 ); -* -* var v = y.get( 0 ); -* // returns false -* -* v = y.get( 2 ); -* // returns false -* -* v = y.get( 4 ); -* // returns true +* var x = toAccessorArray( [ 0, 1, 0, 0, 0 ] ); * -* v = y.get( 6 ); -* // returns true +* var out = toAccessorArray( [ false, false, false, false, false ] ); +* var y = accessors( arraylike2object( x ), arraylike2object( out ), 1, 0, isPositive ); * -* v = y.get( 8 ); +* var v = out.get( 4 ); * // returns true */ -function complex( x, y, stride, offset ) { - var ydata; - var yset; - var flg; - var io; - var i; - - yset = y.accessors[ 1 ]; - ydata = y.data; - - flg = false; - io = offset + (((x.length / 2) - 1) * stride); // Added parentheses to ensure correct order of operations - for ( i = x.length - 2; i >= 0; i -= 2 ) { - if ( flg === false && ( x[ i ] || x[ i + 1 ] ) ) { - flg = true; - } - yset( ydata, io, flg ); - io -= stride; - } - return ydata; +function accessors( x, y, stride, offset, predicate, thisArg ) { + var xdata; + var ydata; + var xget; + var yset; + var flg; + var io; + var i; + + xdata = x.data; + ydata = y.data; + + xget = x.accessors[ 0 ]; + yset = y.accessors[ 1 ]; + + flg = false; + io = offset; + for ( i = xdata.length - 1; i >= 0; i-- ) { + if ( !flg && predicate.call( thisArg, xget( xdata, i ), i, x ) ) { + flg = true; + } + yset( ydata, io, flg ); + io += stride; + } + return ydata; } -/** -* Cumulatively tests whether at least one element in a provided boolean array is truthy, iterating from right to left. -* -* @private -* @param {Collection} x - input array -* @param {Object} y - output array object -* @param {integer} stride - output array stride -* @param {NonNegativeInteger} offset - output array offset -* @returns {Collection} output array -* -* @example -* var Uint8Array = require( '@stdlib/array/uint8' ); -* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); -* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); -* -* var x = new Uint8Array( [ 0, 0, 1, 1, 0 ] ); -* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); -* -* var arr = boolean( x, arraylike2object( y ), 2, 0 ); -* -* var v = y.get( 0 ); -* // returns false -* -* v = y.get( 2 ); -* // returns false -* -* v = y.get( 4 ); -* // returns true -* -* v = y.get( 6 ); -* // returns true -* -* v = y.get( 8 ); -* // returns true -*/ -function boolean( x, y, stride, offset ) { - var ydata; - var yset; - var flg; - var io; - var i; - - yset = y.accessors[ 1 ]; - ydata = y.data; - - flg = false; - io = offset + ((x.length - 1) * stride); // Added parentheses to ensure correct order of operations - for ( i = x.length - 1; i >= 0; i-- ) { - if ( flg === false && x[ i ] ) { - flg = true; - } - yset( ydata, io, flg ); - io -= stride; - } - return ydata; -} // MAIN // /** -* Cumulatively tests whether at least one element in an array is truthy, iterating from right to left, and assigns results to provided output array. +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the output array. * * @param {Collection} x - input array -* @param {Collection} y - output array +* @param {Collection} out - output array * @param {integer} stride - output array stride * @param {NonNegativeInteger} offset - output array offset +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context * @returns {Collection} output array * * @example -* var x = [ false, false, true, false, false ]; -* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* function isPositive( value ) { +* return ( value > 0 ); +* } * -* var out = assign( x, y, 2, 0 ); -* // returns [ false, null, false, null, true, null, true, null, true, null ] +* var x = [ 0, 1, 0, 0 ]; +* +* var y = [ false, null, false, null, false, null, false, null ]; +* var out = assign( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null ] * * var bool = ( y === out ); * // returns true */ -function assign( x, y, stride, offset ) { - var xo = arraylike2object( x ); - var yo = arraylike2object( y ); - if ( xo.accessorProtocol || yo.accessorProtocol ) { - // If provided a complex number array, reinterpret as a real typed array and test interleaved real and imaginary components, where we consider a complex number to be truthy if at least one component is non-zero... - if ( isComplex128Array( x ) ) { - complex( reinterpret128( x, 0 ), yo, stride, offset ); - } else if ( isComplex64Array( x ) ) { - complex( reinterpret64( x, 0 ), yo, stride, offset ); - } else if ( isBooleanArray( x ) ) { - boolean( reinterpretBoolean( x, 0 ), yo, stride, offset ); - } else { - accessors( xo, yo, stride, offset ); - } - return y; - } - indexed( x, y, stride, offset ); - return y; +function assign( x, out, stride, offset, predicate, thisArg ) { + var xo; + var oo; + + xo = arraylike2object( x ); + oo = arraylike2object( out ); + if ( + xo.accessorProtocol || + oo.accessorProtocol + ) { + accessors( xo, oo, stride, offset, predicate, thisArg ); + return out; + } + indexed( x, out, stride, offset, predicate, thisArg ); + return out; } + // EXPORTS // module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/index.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/index.js index 90295df8689..e7108cf8493 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/index.js @@ -19,26 +19,40 @@ 'use strict'; /** -* Cumulatively test whether at least one element in a provided array is truthy, iterating from right to left. +* Cumulatively test whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. * * @module @stdlib/array/base/cuany-by-right * * @example * var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' ); * -* var x = [ false, false, true, false, false ]; +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 1, 0, 0, 0 ]; * * var y = cuanyByRight( x, isPositive ); -* // returns [ false, false, true, true, true ] +* // returns [ false, false, false, true, true ] * * @example * var cuanyByRight = require( '@stdlib/array/base/cuany-by-right' ); * -* var x = [ false, false, true, false, false ]; -* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 1, 0, 0, 0 ]; +* +* var y1 = cuanyByRight( x, isPositive ); +* // returns [ false, false, false, true, true ] * -* var arr = cuanyByRight.assign( x, y, 2, 0, isPositive ); -* // returns [ false, null, false, null, true, null, true, null, true, null ] +* var y2 = [ false, null, false, null, false, null, false, null, false, null ]; +* var out = cuanyByRight.assign( x, y2, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +* +* var bool = ( out === y2 ); +* // returns true */ // MODULES // @@ -56,5 +70,3 @@ setReadOnly( main, 'assign', assign ); // EXPORTS // module.exports = main; - - diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/main.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/main.js index f6cb4314d48..a4f7e4c87bb 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/lib/main.js @@ -27,24 +27,26 @@ var assign = require( './assign.js' ); // MAIN // /** -* Cumulatively tests whether at least one element in an array passes a test implemented by a predicate function, while iterating from right-to-left. +* Cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left. * -* @param {Array} x - input array -* @param {Function} predicate - function which tests array elements +* @param {Collection} x - input array +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context * @returns {Array} output array * * @example -* var x = [ 0, 1, 0, 0, 0 ]; -* function isPositive(value) { -* return (value > 0); +* function isPositive( value ) { +* return ( value > 0 ); * } * -* var y = cuanyByRight(x, isPositive); +* var x = [ 0, 1, 0, 0, 0 ]; +* +* var y = cuanyByRight( x, isPositive ); * // returns [ false, false, false, true, true ] */ -function cuanyByRight(x, predicate) { - var y = filled(false, x.length); - return assign(x, y, 1, 0, predicate); +function cuanyByRight( x, predicate, thisArg ) { + var out = filled( false, x.length ); + return assign( x, out, 1, 0, predicate, thisArg ); } diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/package.json b/lib/node_modules/@stdlib/array/base/cuany-by-right/package.json index e0c07917a88..b9ae4cf3a6f 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/package.json +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/package.json @@ -1,68 +1,68 @@ { - "name": "@stdlib/array/base/cuany-by-right", - "version": "0.0.0", - "description": "Cumulatively test whether at least one element in a provided array is truthy, starting from the rightmost element.", - "license": "Apache-2.0", - "author": { + "name": "@stdlib/array/base/cuany-by-right", + "version": "0.0.0", + "description": "Cumulatively test whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { "name": "The Stdlib Authors", "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdtypes", - "types", - "data", - "structure", - "utils", - "generic", - "array", - "cuany-by-right", - "cumulative", - "test", - "some", - "array.some", - "validate" - ] - } - \ No newline at end of file + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdtypes", + "utils", + "generic", + "array", + "cumulative", + "data", + "structure", + "test", + "predicate", + "any", + "some", + "array.some", + "array-like", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.assign.js index 9a07d31e741..664af9ce086 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.assign.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.assign.js @@ -8,6 +8,7 @@ * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 +* * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,351 +21,227 @@ // MODULES // var tape = require( 'tape' ); -var Complex128Array = require( '@stdlib/array/complex128' ); -var Complex64Array = require( '@stdlib/array/complex64' ); -var BooleanArray = require( '@stdlib/array/bool' ); var Float64Array = require( '@stdlib/array/float64' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var cuanyByRight = require( './../lib/assign.js' ); -// TESTS // - -tape( 'main export is a function', function test( t ) { - t.ok( true, __filename ); - t.strictEqual( typeof cuanyByRight, 'function', 'main export is a function' ); - t.end(); -}); - -tape( 'the function cumulatively tests whether at least one element is truthy (generic)', function test( t ) { - var expected; - var actual; - var x; - var y; - - // Test with a generic array - x = [ true, false, true, false, true ]; - y = [ false, false, false, false, false ]; - actual = cuanyByRight( x, y, 1, 0, Boolean ); - expected = [ false, true, true, true, true ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ false, false, true, false, false ]; - y = [ false, null, false, null, false, null, false, null, false, null ]; - actual = cuanyByRight( x, y, 2, 0, Boolean ); - expected = [ false, null, false, null, false, null, true, null, true, null ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ false, false, true, false, false ]; - y = [ false, false, false, true, true, true ]; - actual = cuanyByRight( x, y, 1, 1, Boolean ); - expected = [ false, false, false, true, true, true ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = []; - y = [ false, false, false, false, false ]; - actual = cuanyByRight( x, y, 1, 0, Boolean ); - expected = [ false, false, false, false, false ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true ]; - y = [ false, false ]; - actual = cuanyByRight( x, y, 1, 1, Boolean ); - expected = [ false, true ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function cumulatively tests whether at least one element is truthy (typed)', function test( t ) { - var expected; - var actual; - var x; - var y; - - // Test with Float64Array - x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); - y = [ false, false, false, false, false ]; - actual = cuanyByRight( x, y, 1, 0, function(value) { return value > 0; } ); - expected = [ true, true, true, true, true ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); - y = [ false, null, false, null, false, null, false, null, false, null ]; - actual = cuanyByRight( x, y, 2, 0, function(value) { return value > 0; } ); - expected = [ false, null, false, null, true, null, true, null, true, null ]; +// FUNCTIONS // - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); +function isPositive( v ) { + return v > 0; +} - x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); - y = [ false, false, false, true, true, true ]; - actual = cuanyByRight( x, y, 1, 1, function(value) { return value > 0; } ); - expected = [ false, false, false, true, true, true ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Float64Array( [] ); - y = [ false, false, false, false, false ]; - actual = cuanyByRight( x, y, 1, 0, function(value) { return value > 0; } ); - expected = [ false, false, false, false, false ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Float64Array( [ 1.0 ] ); - y = [ false, false ]; - actual = cuanyByRight( x, y, 1, 1, function(value) { return value > 0; } ); - expected = [ false, true ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); +// TESTS // - t.end(); +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyByRight, 'function', 'main export is a function' ); + t.end(); }); -tape( 'the function cumulatively tests whether at least one element is truthy (boolean)', function test( t ) { - var expected; - var actual; - var x; - var y; +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array (generic)', function test( t ) { + var expected; + var actual; + var x; + var y; - x = new BooleanArray( [ true, true, true, true, true ] ); - y = [ false, true, false, true, false ]; + x = [ 0, 0, 1, 1, 0 ]; + y = [ false, true, false, true, false ]; - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ true, true, true, true, true ]; + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, true, true, true, true ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - x = new BooleanArray( [ false, false, true, false, false ] ); - y = [ false, null, false, null, false, null, false, null, false, null ]; + x = [ 1, 1, 0, 0 ]; + y = [ false, null, false, null, false, null, false, null ]; - actual = cuanyByRight( x, y, 2, 0 ); - expected = [ false, null, false, null, true, null, true, null, true, null ]; + actual = cuanyByRight( x, y, 2, 0, isPositive ); + expected = [ false, null, false, null, true, null, true, null ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - x = new BooleanArray( [ false, false, true, false, false ] ); - y = [ false, false, false, true, true, true ]; + x = [ 1, 1, 0, 0, 0 ]; + y = [ true, false, false, true, true, true ]; - actual = cuanyByRight( x, y, 1, 1 ); - expected = [ false, false, false, true, true, true ]; + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ true, false, false, false, true, true ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - x = new BooleanArray( [] ); - y = [ false, false, false, false, false ]; + x = []; + y = [ false, false, false, false, false ]; - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ false, false, false, false, false ]; + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - x = new BooleanArray( [ true ] ); - y = [ false, false ]; + x = [ 0 ]; + y = [ false, false ]; - actual = cuanyByRight( x, y, 1, 1 ); - expected = [ false, true ]; + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ false, false ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); + t.end(); }); -tape( 'the function cumulatively tests whether at least one element is truthy (complex128)', function test( t ) { - var expected; - var actual; - var x; - var y; +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array (typed)', function test( t ) { + var expected; + var actual; + var x; + var y; - x = new Complex128Array( [ 1.0, 0.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0 ] ); - y = [ false, true, false, true, false ]; + x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 0.0 ] ); + y = [ false, true, false, true, false ]; - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ true, true, true, true, true ]; + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, true, true, true ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - x = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] ); - y = [ false, null, false, null, false, null, false, null, false, null ]; + x = new Float64Array( [ 1.0, 1.0, 0.0, 0.0 ] ); + y = [ false, null, false, null, false, null, false, null ]; - actual = cuanyByRight( x, y, 2, 0 ); - expected = [ false, null, false, null, true, null, true, null, true, null ]; + actual = cuanyByRight( x, y, 2, 0, isPositive ); + expected = [ false, null, false, null, true, null, true, null ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - x = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - y = [ false, false, false, true, true, true ]; + x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); + y = [ true, false, false, true, true, true ]; - actual = cuanyByRight( x, y, 1, 1 ); - expected = [ false, false, false, true, true, true ]; + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ true, false, false, true, true, true ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - x = new Complex128Array( [] ); - y = [ false, false, false, false, false ]; + x = new Float64Array( [] ); + y = [ false, false, false, false, false ]; - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ false, false, false, false, false ]; + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - x = new Complex128Array( [ 1.0, 1.0 ] ); - y = [ false, false ]; + x = new Float64Array( [ 0.0 ] ); + y = [ false, false ]; - actual = cuanyByRight( x, y, 1, 1 ); - expected = [ false, true ]; + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ false, false ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); + t.end(); }); -tape( 'the function cumulatively tests whether at least one element is truthy (complex64)', function test( t ) { - var expected; - var actual; - var x; - var y; +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array (accessor)', function test( t ) { + var expected; + var actual; + var ybuf; + var x; + var y; - x = new Complex64Array( [ 0.0, 1.0, 1.0, 0.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0 ] ); - y = [ false, true, false, true, false ]; + x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); + ybuf = [ false, true, false, true, false ]; + y = toAccessorArray( ybuf ); - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ true, true, true, true, true ]; + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, true ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); - x = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] ); - y = [ false, null, false, null, false, null, false, null, false, null ]; + x = toAccessorArray( [ 0, 1, 1, 0 ] ); + ybuf = [ false, null, false, null, false, null, false, null ]; + y = toAccessorArray( ybuf ); - actual = cuanyByRight( x, y, 2, 0 ); - expected = [ false, null, false, null, true, null, true, null, true, null ]; + actual = cuanyByRight( x, y, 2, 0, isPositive ); + expected = [ false, null, true, null, true, null, true, null ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); - x = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - y = [ false, false, false, true, true, true ]; + x = toAccessorArray( [ 0, 1, 1, 0, 0 ] ); + ybuf = [ true, false, false, false, false, false ]; + y = toAccessorArray( ybuf ); - actual = cuanyByRight( x, y, 1, 1 ); - expected = [ false, false, false, true, true, true ]; + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ true, false, false, true, true, true ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); - x = new Complex64Array( [] ); - y = [ false, false, false, false, false ]; + x = toAccessorArray( [ 0, 0, 0, 0, 1 ] ); + ybuf = [ true, true, true, true, true ]; + y = toAccessorArray( ybuf ); - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ false, false, false, false, false ]; + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ true, true, true, true, true ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Complex64Array( [ 1.0, 1.0 ] ); - y = [ false, false ]; - - actual = cuanyByRight( x, y, 1, 1 ); - expected = [ false, true ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); -tape( 'the function cumulatively tests whether at least one element is truthy (accessor)', function test( t ) { - var expected; - var actual; - var ybuf; - var x; - var y; + x = toAccessorArray( [] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); - x = toAccessorArray( [ true, false, true, false, true ] ); - ybuf = [ false, true, false, true, false ]; - y = toAccessorArray( ybuf ); + actual = cuanyByRight( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ true, true, true, true, true ]; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); + x = toAccessorArray( [ 0 ] ); + ybuf = [ false, false ]; + y = toAccessorArray( ybuf ); - x = toAccessorArray( [ false, false, true, false, false ] ); - ybuf = [ false, null, false, null, false, null, false, null, false, null ]; - y = toAccessorArray( ybuf ); + actual = cuanyByRight( x, y, 1, 1, isPositive ); + expected = [ false, false ]; - actual = cuanyByRight( x, y, 2, 0 ); - expected = [ false, null, false, null, true, null, true, null, true, null ]; + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - x = toAccessorArray( [ false, false, true, false, false ] ); - ybuf = [ false, false, false, false, false, false ]; - y = toAccessorArray( ybuf ); - - actual = cuanyByRight( x, y, 1, 1 ); - expected = [ false, false, false, true, true, true ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - x = toAccessorArray( [ true, false, false, false, false ] ); - ybuf = [ false, false, false, false, false ]; - y = toAccessorArray( ybuf ); - - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ true, true, true, true, true ]; - - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); - - x = toAccessorArray( [] ); - ybuf = [ false, false, false, false, false ]; - y = toAccessorArray( ybuf ); + t.end(); +}); - actual = cuanyByRight( x, y, 1, 0 ); - expected = [ false, false, false, false, false ]; +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); + ctx = { + 'count': 0 + }; - x = toAccessorArray( [ true ] ); - ybuf = [ false, false ]; - y = toAccessorArray( ybuf ); + x = [ 0, 1, 0, 0, 0 ]; + y = [ false, null, false, null, false, null, false, null, false, null ]; - actual = cuanyByRight( x, y, 1, 1 ); - expected = [ false, true ]; + actual = cuanyByRight( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, false, null, true, null, true, null ]; - t.strictEqual( actual, y, 'returns expected value' ); - t.deepEqual( ybuf, expected, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + t.end(); - t.end(); + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } }); - - diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.js index ea5f3412121..6a65e1ab20c 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.js @@ -39,5 +39,3 @@ tape( 'attached to the main export is an `assign` method', function test( t ) { t.strictEqual( hasMethod( cuanyByRight, 'assign' ), true, 'returns expected value' ); t.end(); }); - - diff --git a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.main.js b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.main.js index 71b7b2ab785..8ee001ff5a2 100644 --- a/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/cuany-by-right/test/test.main.js @@ -21,14 +21,22 @@ // MODULES // var tape = require( 'tape' ); -var Complex128Array = require( '@stdlib/array/complex128' ); -var Complex64Array = require( '@stdlib/array/complex64' ); -var BooleanArray = require( '@stdlib/array/bool' ); var Float64Array = require( '@stdlib/array/float64' ); var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var cuanyByRight = require( './../lib' ); +// FUNCTIONS // + +function isPositive( v ) { + return v > 0; +} + +function isNotNull( v ) { + return v !== null; +} + + // TESTS // tape( 'main export is a function', function test( t ) { @@ -37,206 +45,117 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -function isPositive(value) { - return (value > 0); -} - -tape( 'the function cumulatively tests whether at least one element is truthy (generic)', function test( t ) { +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (generic)', function test( t ) { var expected; var actual; var x; - x = [ false, false, true, false, false ]; - actual = cuanyByRight(x) - expected = [ true, true, true, true, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); + x = [ 1, 1, 0, 0, 0 ]; - x = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; actual = cuanyByRight( x, isPositive ); - expected = [ false, false, false, false, false ]; + expected = [ false, false, false, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = [ true, true, true, true, true ]; + x = [ 0.0, 0.0, 0.0, 1.0, 1.0 ]; actual = cuanyByRight( x, isPositive ); expected = [ true, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = [ null, {}, null ]; - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = [ true, false, false, false, false ]; - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true ]; + x = [ {}, {}, null ]; + actual = cuanyByRight( x, isNotNull ); + expected = [ false, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); -tape( 'the function cumulatively tests whether at least one element is truthy (typed)', function test( t ) { - var expected; - var actual; - var x; - - x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, false, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ false, false, false, false, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); -}); - -tape( 'the function cumulatively tests whether at least one element is truthy (boolean)', function test( t ) { +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (typed)', function test( t ) { var expected; var actual; var x; - x = new BooleanArray( [ false, false, true, false, false ] ); + x = new Float64Array( [ 0.0, 0.0, 1.0, 1.0, 0.0 ] ); actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, false, false ]; + expected = [ false, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = new BooleanArray( [ false, false, false, false, false ] ); + x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); actual = cuanyByRight( x, isPositive ); expected = [ false, false, false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = new BooleanArray( [ true, true, true, true, true ] ); + x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] ); actual = cuanyByRight( x, isPositive ); expected = [ true, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = new BooleanArray( [ false, true, true ] ); + x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); actual = cuanyByRight( x, isPositive ); - expected = [ true, true, false ]; + expected = [ false, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = new BooleanArray( [ true, false, true, false, false ] ); + x = new Float64Array( [ 0.0, 1.0, 0.0, 0.0, 0.0 ] ); actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, false ]; + expected = [ false, false, false, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); t.end(); }); -tape( 'the function cumulatively tests whether at least one element is truthy (complex128)', function test( t ) { +tape( 'the function cumulatively tests whether at least one array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (accessor)', function test( t ) { var expected; var actual; var x; - x = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + x = toAccessorArray( [ 1, 1, 0, 0, 0 ] ); + actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, false ]; + expected = [ false, false, false, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = new Complex128Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + x = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); actual = cuanyByRight( x, isPositive ); expected = [ false, false, false, false, false ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = new Complex128Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); + x = toAccessorArray( [ 1, 1, 1, 1, 1 ] ); actual = cuanyByRight( x, isPositive ); expected = [ true, true, true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = new Complex128Array( [ 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 ] ); + x = toAccessorArray( [ 0, 0, 1 ] ); actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, false, false ]; + expected = [ true, true, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - x = new Complex128Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] ); + x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true ]; + expected = [ false, false, false, false, true ]; t.deepEqual( actual, expected, 'returns expected value' ); - t.end(); }); -tape( 'the function cumulatively tests whether at least one element is truthy (complex64)', function test( t ) { +tape( 'the function supports providing an execution context', function test( t ) { var expected; - var actual; + var out; + var ctx; var x; - x = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true, false, false, false, false, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); + ctx = { + 'count': 0 + }; - x = new Complex64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ false, false, false, false, false, false, false, false, false, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); + x = [ 1, -2, 0, -1 ]; - x = new Complex64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true, true, true, true, true, true ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Complex64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, false, false, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = new Complex64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0 ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true, true, false, false, false, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); + out = cuanyByRight( x, predicate, ctx ); + expected = [ false, false, false, true ]; + t.deepEqual( out, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); t.end(); -}); - -tape( 'the function cumulatively tests whether at least one element of an accessor array is truthy (accessor)', function test( t ) { - var expected; - var actual; - var x; - x = toAccessorArray( [ false, false, true, false, false ] ); - - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, false, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ false, false, false, false, false ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ false, false, false, false, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ true, true, true, true, true ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ false, true, false ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, false ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - x = toAccessorArray( [ true, false, false, false, false ] ); - actual = cuanyByRight( x, isPositive ); - expected = [ true, true, true, true, true ]; - t.deepEqual( actual, expected, 'returns expected value' ); - - t.end(); + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } }); -