diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/README.md b/lib/node_modules/@stdlib/array/base/cuany-by/README.md new file mode 100644 index 000000000000..0cd13c508b49 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/README.md @@ -0,0 +1,153 @@ + + +# cuanyBy + +> Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function. + +
+ +## Usage + +```javascript +var cuanyBy = require( '@stdlib/array/base/cuany-by' ); +``` + +#### cuanyBy( x, predicate\[, thisArg] ) + +Cumulatively tests whether at least one element in a provided array passes a test implemented by a `predicate` function. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var x = [ 0, 0, 0, 1, 0 ]; + +var y = cuanyBy( x, isPositive ); +// returns [ false, false, false, 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, 0, 0, 1, 0 ]; + +var context = { + 'count': 0 +}; + +var out = cuanyBy( x, isPositive, context ); +// returns [ false, false, false, true, true ] + +var cnt = context.count; +// returns 4 +``` + +#### cuanyBy.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 and assigns results to a provided output array. + +```javascript +function isPositive( value ) { + return ( value > 0 ); +} + +var x = [ 0, 0, 0, 1, 0 ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cuanyBy.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 cuanyBy = require( '@stdlib/array/base/cuany-by' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.1 ); +console.log( x ); + +var out = cuanyBy( x, isPositive ); +console.log( out ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.assign.length.js new file mode 100644 index 000000000000..0797a8a186e2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.assign.length.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var filled = require( '@stdlib/array/base/filled' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var pkg = require( './../package.json' ).name; +var cuanyBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + 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; + + y = filled( false, len ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyBy.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(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + 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 ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.js new file mode 100644 index 000000000000..7dd6251a8131 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isArray = require( '@stdlib/assert/is-array' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var pkg = require( './../package.json' ).name; +var cuanyBy = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var i; + var v; + + x = [ 0, 0, 1, 0, 1 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyBy( 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(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.length.js new file mode 100644 index 000000000000..95bdb17659d6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/benchmark/benchmark.length.js @@ -0,0 +1,96 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var isArray = require( '@stdlib/assert/is-array' ); +var filled = require( '@stdlib/array/base/filled' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var pkg = require( '@stdlib/array/base/cuany-by/package.json' ).name; +var cuanyBy = require( '@stdlib/array/base/cuany-by/lib' ); + + +// FUNCTIONS // + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var x = filled( 1.5, len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cuanyBy( 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(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( pkg+':len='+len, f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cuany-by/docs/repl.txt new file mode 100644 index 000000000000..4b8a14267f06 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/docs/repl.txt @@ -0,0 +1,73 @@ + +{{alias}}( x, predicate[, thisArg] ) + Cumulatively tests whether at least one element in a provided array + passes a test implemented by a predicate function. + + 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 + Output array. + + Examples + -------- + > function f( v ) { return ( v > 0 ); }; + > var x = [ 0, 0, 0, 1, 0 ]; + > var out = {{alias}}( x, f ) + [ false, false, false, true, true ] + + +{{alias}}.assign( x, y, stride, offset, predicate[, thisArg] ) + Cumulatively tests whether at least one element in a provided array + passes a test implemented by a predicate function and assigns results + to a provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + y: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + predicate: Function + Predicate function. + + Returns + ------- + y: ArrayLikeObject + Output array. + + Examples + -------- + > function f( v ) { return ( v > 0 ); }; + > var x = [ 0, 0, 0, 1, 0 ]; + > var y = [ false, null, false, null, false, null, false, null, false ]; + > var result = {{alias}}.assign( x, y, 2, 0, f ) + [ false, null, false, null, false, null, true, null, true ] + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/index.d.ts new file mode 100644 index 000000000000..fd614758464a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/index.d.ts @@ -0,0 +1,203 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/// + +import { Collection, AccessorArrayLike, TypedArray, BooleanArray } from '@stdlib/types/array'; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @returns boolean indicating whether an element passes a test +*/ +type Nullary = ( this: U ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @returns boolean indicating whether an element passes a test +*/ +type Unary = ( this: U, value: T ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @returns boolean indicating whether an element passes a test +*/ +type Binary = ( this: U, value: T, index: number ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param arr - input array +* @returns boolean indicating whether an element passes a test +*/ +type Ternary = ( this: U, value: T, index: number, arr: Collection | AccessorArrayLike ) => boolean; + +/** +* Returns a boolean indicating whether an element passes a test. +* +* @param value - current array element +* @param index - current array element index +* @param arr - input array +* @returns boolean indicating whether an element passes a test +*/ +type Predicate = Nullary | Unary | Binary | Ternary; + +/** +* Interface describing `cunanyBy`. +*/ +interface CuAnyBy { + /** + * Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function. + * + * @param x - input array + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns output array + * + * @example + * + * function isPositive( v ) { + * return v > 0; + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * + * var y = cuanyBy( x, isPositive ); + * // returns [ false, false, false, true, true ]; + */ + ( x: Collection | AccessorArrayLike, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function and assigns the results to a provided output array. + * + * @param x - input array + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return v > 0; + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = [ false, null, false, null, false, null, true, null, true, null ]; + * + * var arr = cuanyBy.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 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, 1, 0, 1, 0 ]; + * var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] ); + * + * var arr = cuanyBy.assign( x, y, 2, 0, isPositive ); + * // returns + * + * var v = arr.get( 4 ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; + + /** + * Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function and assigns the results to a provided output array. + * + * @param x - input array + * @param y - output array + * @param stride - output array stride + * @param offset - output array offset + * @param predicate - predicate function + * @param thisArg - predicate function execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return v > 0; + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * var y = [ false, null, false, null, false, null, true, null, true, null ]; + * + * var arr = cuanyBy.assign( x, y, 2, 0, isPositive );, + * // returns [ false, null, false, null, false, null, true, null, true, null ]; + */ + 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 passes a test implemented by a predicate function. +* +* @param x - input array +* @returns output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* +* var y = cuanyBy( x, isPositive ); +* // returns [ false, false, false, true, true ] +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cuanyBy.assign( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +*/ +declare var cuanyBy: CuAnyBy; + + +// EXPORTS // + +export = cuanyBy; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/test.ts new file mode 100644 index 000000000000..09050fe89e2b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/docs/types/test.ts @@ -0,0 +1,220 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + + +import cuanyBy = 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... +{ + cuanyBy( [ 1, 2, 3 ], isPositive ); // $ExpectType boolean[] + cuanyBy( new Float64Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Float32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Int32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Int16Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Int8Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Uint32Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Uint16Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Uint8Array( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + cuanyBy( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive ); // $ExpectType boolean[] + + cuanyBy( [ 1, 2, 3 ], isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Float64Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Float32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Int32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Int16Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Int8Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Uint32Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Uint16Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Uint8Array( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] + cuanyBy( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not like a function.. +{ + const x = [ 1, 2, 3, 4 ]; + + cuanyBy( x, null ); // $ExpectError + cuanyBy( x, {} ); // $ExpectError + cuanyBy( x, [] ); // $ExpectError + cuanyBy( x, '' ); // $ExpectError + cuanyBy( x, undefined ); // $ExpectError + + cuanyBy( x, null, {} ); // $ExpectError + cuanyBy( x, {}, {} ); // $ExpectError + cuanyBy( x, [], {} ); // $ExpectError + cuanyBy( x, '', {} ); // $ExpectError + cuanyBy( x, undefined, {} ); // $ExpectError + +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cuanyBy(); // $ExpectError + cuanyBy( [] ); // $ExpectError + cuanyBy( [ 1, 2 ], isPositive, {}, '' ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ 0, 0, 0, 1, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyBy.assign( x, y, 2, 0, isPositive ); // $ExpectType (boolean | null)[] + cuanyBy.assign( x, y, 2, 0, isPositive, {} ); // $ExpectType (boolean | null)[] + cuanyBy.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array + cuanyBy.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array + cuanyBy.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array + cuanyBy.assign( x, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array + cuanyBy.assign( x, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array + cuanyBy.assign( x, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array + cuanyBy.assign( x, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array + cuanyBy.assign( x, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array + cuanyBy.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray + + cuanyBy.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[] + cuanyBy.assign( x, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array + cuanyBy.assign( x, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array + cuanyBy.assign( x, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array + cuanyBy.assign( x, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array + cuanyBy.assign( x, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array + cuanyBy.assign( x, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array + cuanyBy.assign( x, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array + cuanyBy.assign( x, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array + cuanyBy.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 ]; + + cuanyBy.assign( 1, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( true, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( false, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( null, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( void 0, x, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( {}, x, 2, 0, isPositive ); // $ExpectError + + cuanyBy.assign( 1, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( true, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( false, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( null, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( void 0, x, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.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 ]; + + cuanyBy.assign( x, 1, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, true, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, false, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, null, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, void 0, 2, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, {}, 2, 0, isPositive ); // $ExpectError + + cuanyBy.assign( x, 1, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, true, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, false, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, null, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, void 0, 2, 0, isPositive, {} ); // $ExpectError + cuanyBy.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 ]; + + cuanyBy.assign( x, y , '1', 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , true, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , false, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , null, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , void 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , {}, 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y , [], 0, isPositive ); // $ExpectError + + cuanyBy.assign( x, y , '1', 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , true, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , false, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , null, 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , void 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y , {}, 0, isPositive, {} ); // $ExpectError + cuanyBy.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... +{ + const x = [ false, false, true, false, false ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cuanyBy.assign( x, y, 1, '1', isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, true, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, false, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, null, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, void 0, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, {}, isPositive ); // $ExpectError + cuanyBy.assign( x, y, 1, [], isPositive ); // $ExpectError + + cuanyBy.assign( x, y, 1, '1', isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, true, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, false, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, null, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, void 0, isPositive, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, {}, isPositive, {} ); // $ExpectError + cuanyBy.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 ]; + + cuanyBy.assign( x, y, 1, 2, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, 2, void 0 ); // $ExpectError + cuanyBy.assign( x, y, 1, 1, [] ); // $ExpectError + cuanyBy.assign( x, y, 1, 1, '' ); // $ExpectError + + cuanyBy.assign( x, y, 1, 2, {}, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, 2, void 0, {} ); // $ExpectError + cuanyBy.assign( x, y, 1, 1, [], {} ); // $ExpectError + cuanyBy.assign( x, y, 1, 1, '', {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cuanyBy.assign(); // $ExpectError + cuanyBy.assign( [] ); // $ExpectError + cuanyBy.assign( [], [] ); // $ExpectError + cuanyBy.assign( [], [], 2 ); // $ExpectError + cuanyBy.assign( [], [], 1, 1, isPositive, [], {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/examples/index.js b/lib/node_modules/@stdlib/array/base/cuany-by/examples/index.js new file mode 100644 index 000000000000..8c0cf648601a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/examples/index.js @@ -0,0 +1,31 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var cuanyBy = require( './../lib' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.1 ); +console.log( x ); + +// Cumulatively determine whether values are truthy: +var out = cuanyBy( x, isPositiveInteger ); +console.log( out ); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/lib/assign.js b/lib/node_modules/@stdlib/array/base/cuany-by/lib/assign.js new file mode 100644 index 000000000000..ecc4e6b90831 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/lib/assign.js @@ -0,0 +1,180 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + + +// FUNCTIONS // + +/** +* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function. +* +* @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 +* function isPositive( v ) { +* return v > 0; +* } +* +* var x = [ false, false, false, true, false ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var out = indexed( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +*/ +function indexed( x, y, stride, offset, predicate, thisArg ) { + var flg; + var io; + var i; + + flg = false; + io = offset; + for ( i = 0; i < x.length; 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 array passes a test implemented by a predicate function. +* +* @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 +* function isPositive( v ) { +* return v > 0; +* } +* +* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +* var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); +* +* var x = toAccessorArray( [ false, false, false, true, false ] ); +* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); +* +* var arr = accessors( arraylike2object( x ), arraylike2object( y ), 2, 0, isPositive ); +* +* var v = y.get( 0 ); +* // returns false +* +* v = y.get( 2 ); +* // returns false +* +* v = y.get( 4 ); +* // returns false +* +* v = y.get( 6 ); +* // returns true +* +* v = y.get( 8 ); +* // returns true +*/ +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 = 0; i < xdata.length; i++ ) { + if ( !flg && predicate.call( thisArg, xget( xdata, i ), i, x ) ) { + flg = true; + } + yset( ydata, io, flg ); + io += stride; + } + return ydata; +} + + +// MAIN // + +/** +* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function and assigns results to provided output array. +* +* @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 +* 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 out = assign( x, y, 2, 0, isPositive ); +// returns [ false, null, false, null, false, null, true, null, true, null ] +* +* var bool = ( y === out ); +* // returns true +*/ +function assign( x, y, stride, offset, predicate, thisArg ) { + var xo = arraylike2object( x ); + var yo = arraylike2object( y ); + + if ( + xo.accessorProtocol || + yo.accessorProtocol + ) { + return accessors( xo, yo, stride, offset, predicate, thisArg ); + } + indexed( x, y, stride, offset, predicate, thisArg ); + return y; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/lib/index.js b/lib/node_modules/@stdlib/array/base/cuany-by/lib/index.js new file mode 100644 index 000000000000..38b0b7bd9669 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/lib/index.js @@ -0,0 +1,66 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function. +* +* @module @stdlib/array/base/cuany-by +* +* @example +* var cuanyBy = require( '@stdlib/array/base/cuany-by' ); +* +* function isPositive( v ) { +* return v > 0; +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* +* var y = cuanyBy( x, isPositive ); +* // returns [ false, false, false, true, true ] +* +* @example +* var cuanyBy = require( '@stdlib/array/base/cuany-by' ); +* +* 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 = cuanyBy.assign( x, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, true, null, true, null ] +*/ + +// MODULES // + +var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' ); +var main = require( './main.js' ); +var assign = require( './assign.js' ); + + +// MAIN // + +setReadOnly( main, 'assign', assign ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/lib/main.js b/lib/node_modules/@stdlib/array/base/cuany-by/lib/main.js new file mode 100644 index 000000000000..92505823fac9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/lib/main.js @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var filled = require( '@stdlib/array/base/filled' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function. +* +* @param {Collection} x - input array +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Array} output array +* +* @example +* function isPositive( v ) { +* return v > 0; +* } +* +* var x = [ 0, 0, 0, 1, 0 ]; +* +* var y = cuanyBy( x, isPositive ); +* // returns [ false, false, false, true, true ] +*/ +function cuanyBy( x, predicate, thisArg ) { + var y = filled( false, x.length ); + return assign( x, y, 1, 0, predicate, thisArg ); +} + + +// EXPORTS // + +module.exports = cuanyBy; diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/package.json b/lib/node_modules/@stdlib/array/base/cuany-by/package.json new file mode 100644 index 000000000000..09b579ad405f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/cuany", + "version": "0.0.0", + "description": "Cumulatively test whether at least one element in a provided array passes a test implemented by a predicate function.", + "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" + } + ], + "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", + "cumulative", + "test", + "some", + "array.some", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.assign.js new file mode 100644 index 000000000000..6729e9eb6b7a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.assign.js @@ -0,0 +1,304 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cuanyBy = require( './../lib/assign.js' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + x = [ true, false, true, false, true ]; + y = [ false, true, false, true, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ true, 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 = cuanyBy( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, true, 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 = cuanyBy( x, y, 1, 1, predicate, ctx ); + 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 = cuanyBy( x, y, 1, 0, predicate, ctx ); + 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 = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return value; + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (typed)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + x = new Float64Array( [ 1.0, 0.0, 1.0, 0.0, 1.0 ] ); + y = [ false, true, false, true, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + 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 = cuanyBy( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + 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, false, false, true, true, true ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + 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 = cuanyBy( x, y, 1, 0, predicate, ctx ); + 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 = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( value > 0 ); + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (boolean)', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + x = new BooleanArray( [ true, true, true, true, true ] ); + y = [ false, true, false, true, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ true, true, true, true, true ]; + + 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 ]; + + actual = cuanyBy( x, y, 2, 0, predicate, ctx ); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + 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 ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [] ); + y = [ false, false, false, false, false ]; + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true ] ); + y = [ false, false ]; + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( value > 0 ); + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (accessor)', function test( t ) { + var expected; + var actual; + var ybuf; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + x = toAccessorArray( [ true, false, true, false, true ] ); + ybuf = [ false, true, false, true, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ true, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, true, false, false ] ); + ybuf = [ false, null, false, null, false, null, false, null, false, null ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 2, 0, predicate, ctx ); + 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' ); + + x = toAccessorArray( [ false, false, true, false, false ] ); + ybuf = [ false, false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + 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 = cuanyBy( x, y, 1, 0, predicate, ctx ); + 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 ); + + actual = cuanyBy( x, y, 1, 0, predicate, ctx ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ true ] ); + ybuf = [ false, false ]; + y = toAccessorArray( ybuf ); + + actual = cuanyBy( x, y, 1, 1, predicate, ctx ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + this.count += 1; // eslint-disable-line no-invalid-this + return value; + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/test/test.js b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.js new file mode 100644 index 000000000000..21a2aeb99033 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var hasMethod = require( '@stdlib/assert/is-method' ); +var cuanyBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cuanyBy, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( cuanyBy, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuany-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.main.js new file mode 100644 index 000000000000..9c2ffa587af6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuany-by/test/test.main.js @@ -0,0 +1,185 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 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. +* 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. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var BooleanArray = require( '@stdlib/array/bool' ); +var Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cuanyBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cuanyBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ false, false, true, false, false ]; + actual = cuanyBy( x, predicate ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0.0, 0.0, 0.0, 0.0, 0.0 ]; + actual = cuanyBy( x, predicate ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, true, true, true, true ]; + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ null, {}, null ]; + actual = cuanyBy( x, predicate ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, false, false, false, false ]; + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + return value; + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (typed)', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 0.0 ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cuanyBy( x, predicate ); + 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 = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 0.0 ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + return ( value > 0 ); + } +}); + +tape( 'the function cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function (boolean)', function test( t ) { + var expected; + var actual; + var x; + + x = new BooleanArray( [ false, false, true, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, false, false, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true, true, true, true, true ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ false, true, true ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new BooleanArray( [ true, false, true, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + return value; + } +}); + +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 = cuanyBy( x, predicate ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, false, false, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ true, true, true, true, true ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ false, true, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ true, false, false, false, false ] ); + actual = cuanyBy( x, predicate ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); + + function predicate( value ) { + return value; + } +});