diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/README.md b/lib/node_modules/@stdlib/array/base/cuevery-by/README.md new file mode 100644 index 000000000000..346246a63270 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/README.md @@ -0,0 +1,145 @@ + + +# cueveryBy + +> Cumulatively test whether every array element in a provided array passes a test implemented by a predicate function. + +
+ +## Usage + +```javascript +var cueveryBy = require( '@stdlib/array/base/cuevery-by' ); +``` + +#### cueveryBy( x, predicate\[, thisArg ] ) + +Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. + +```javascript +function fcn( value) { + return ( value > 0 ); +} + +var x = [ 1, 1, 0, 0, 0 ]; + +var y = cueveryBy( x, fcn ); +// returns [ true, true, false, false, false ] +``` + +The invoked `predicate` function is provided three arguments: + +- **value**: collection element. +- **index**: collection index. +- **collection**: input collection. + +To set the function execution context, provide a `thisArg`. + +```javascript +function fcn( v ) { + this.count += 1; + return ( v > 0 ); +} + +var x = [ 1, 1, 0, 0, 0 ]; + +var context = { + 'count': 0 +}; + +var bool = cueveryBy( x, fcn, context ); +// returns [ true, true, false, false, false ] + +var count = context.count; +// returns 3 +``` + +#### cueveryBy.assign( x, out, stride, offset, predicate\[, thisArg ] ) + +Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function and assigns the results to a provided output array. + +```javascript +function fcn( v ) { + return ( v > 0 ); +} + +var x = [ 1, 1, 0, 0, 0 ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cueveryBy.assign( x, y, 2, 0, fcn ); +// returns [ true, null, true, null, false, null, false, null, false, null ] + +var bool = ( out === y ); +// returns true +``` + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cueveryBy = require( '@stdlib/array/base/cuevery-by' ); + +function fcn( value ) { + return ( value > 0 ); +} + +// Create an array of random values: +var x = bernoulli( 10, 0.8 ); +console.log( x ); + +// Cumulatively tests whether every array element passes a test: +var y = cueveryBy( x, fcn ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.assign.length.js new file mode 100644 index 000000000000..31344ed8ebaa --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cueveryBy = 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 = cueveryBy.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/cuevery-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.js new file mode 100644 index 000000000000..83b7a4f2869d --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.js @@ -0,0 +1,53 @@ +/** +* @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 zeroTo = require( '@stdlib/array/base/zero-to' ); +var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var cueveryBy = require( './../lib' ); + + +// MAIN // + +bench( pkg+'::copy:len=100', function benchmark( b ) { + var x; + var i; + var v; + + x = zeroTo( 100 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cueveryBy( 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/cuevery-by/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cuevery-by/benchmark/benchmark.length.js new file mode 100644 index 000000000000..6519dd9bbe08 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ); +var filled = require( '@stdlib/array/base/filled' ); +var pkg = require( './../package.json' ).name; +var cueveryBy = 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 v; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cueveryBy( 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/cuevery-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/repl.txt new file mode 100644 index 000000000000..4afd732fafa4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/repl.txt @@ -0,0 +1,77 @@ + +{{alias}}( x, predicate[, thisArg] ) + Cumulatively tests whether every array 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 fcn( v ) { return ( v > 0 ); }; + > var x = [ 1, 1, 0, 0, 0 ]; + > var y = {{alias}}( x, fcn ) + [ true, true, false, false, false ] + + +{{alias}}.assign( x, out, stride, offset, predicate[, thisArg] ) + Cumulatively tests whether every array element in a provided array passes a + test implemented by a predicate function and assigns the values to elements + in a provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + out: ArrayLikeObject + Output array. + + stride: integer + Output array stride. + + offset: integer + Output array offset. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: ArrayLikeObject + Output array. + + Examples + -------- + > function fcn( 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, fcn ) + [ true, null, true, null, false, null, false, null ] + > var bool = ( arr === out ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/index.d.ts new file mode 100644 index 000000000000..728e8d24f882 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/index.d.ts @@ -0,0 +1,200 @@ +/* +* @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'; + +/** +* 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 `cueveryBy`. +*/ +interface CuEveryBy { + /** + * Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. + * + * @param x - input array + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 1, 1, 1, 0, 0 ]; + * + * var y = cueveryBy( x, isPositive ); + * // returns [ true, true, true, false, false ]; + */ + ( x: Collection | AccessorArrayLike, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether every 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 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 = cueveryBy.assign( x, y, 2, 0, isPositive );, + * // returns [ true, null, true, null, false, null, false, null, false, null ]; + */ + assign( x: Collection | AccessorArrayLike, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether every 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, 0, 0, 1, 0 ]; + * var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] ); + * + * var arr = cueveryBy.assign( x, y, 2, 0, isPositive ); + * // returns + * + * var v = arr.get( 4 ); + * // returns false + */ + assign( x: Collection | AccessorArrayLike, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; + + /** + * Cumulatively tests whether every 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 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 = cueveryBy.assign( x, y, 2, 0, isPositive );, + * // returns [ true, null, true, null, false, null, false, null, false, null ]; + */ + assign( x: Collection | AccessorArrayLike, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; + +} + +/** +* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. +* +* @param x - input array +* @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 result = cueveryBy( x, isPositive ); +* // returns [ true, true, false, false, false ] +* +* @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 = cueveryBy.assign( x, y, 2, 0, isPositive ); +* // returns [ true, null, true, null, false, null, false, null, false, null ]; +*/ +declare var cueveryBy: CuEveryBy; + + +// EXPORTS // + +export = cueveryBy; diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/test.ts new file mode 100644 index 000000000000..bf19f6906ed4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/docs/types/test.ts @@ -0,0 +1,205 @@ +/* +* @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 cueveryBy = require( './index' ); + +const isPositive = ( v: number ): boolean => { + return ( v > 0 ); +}; + + +// TESTS // + +// The function returns an array... +{ + cueveryBy( [ 1, 2, 3, 4 ], isPositive ); // $ExpectType boolean[] + cueveryBy( [ 1, 2, 3, 4 ], isPositive ); // $ExpectType boolean[] + + cueveryBy( [ 1, 2, 3, 4 ], isPositive, {} ); // $ExpectType boolean[] + cueveryBy( [ 1, 2, 3, 4 ], isPositive, {} ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + cueveryBy( 1, isPositive ); // $ExpectError + cueveryBy( true, isPositive ); // $ExpectError + cueveryBy( false, isPositive ); // $ExpectError + cueveryBy( null, isPositive ); // $ExpectError + cueveryBy( void 0, isPositive ); // $ExpectError + cueveryBy( {}, isPositive ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not an array-like object containing numbers... +{ + cueveryBy( [], 1 ); // $ExpectError + cueveryBy( [], true ); // $ExpectError + cueveryBy( [], false ); // $ExpectError + cueveryBy( [], null ); // $ExpectError + cueveryBy( [], void 0 ); // $ExpectError + cueveryBy( [], {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cueveryBy(); // $ExpectError + cueveryBy( [] ); // $ExpectError + cueveryBy( [], [], 'throw', {} ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ 1, 2, 3, 4 ]; + + cueveryBy.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive ); // $ExpectType (number | boolean)[] + cueveryBy.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array + cueveryBy.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array + cueveryBy.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array + cueveryBy.assign( x, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array + cueveryBy.assign( x, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array + cueveryBy.assign( x, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array + cueveryBy.assign( x, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array + cueveryBy.assign( x, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array + cueveryBy.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray + + cueveryBy.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[] + cueveryBy.assign( x, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array + cueveryBy.assign( x, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array + cueveryBy.assign( x, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array + cueveryBy.assign( x, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array + cueveryBy.assign( x, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array + cueveryBy.assign( x, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array + cueveryBy.assign( x, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array + cueveryBy.assign( x, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array + cueveryBy.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 = [ 1, 1, 0, 0, 0 ]; + + cueveryBy.assign( 1, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( true, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( false, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( null, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( void 0, x, 2, 0, isPositive ); // $ExpectError + cueveryBy.assign( {}, x, 2, 0, isPositive ); // $ExpectError + + cueveryBy.assign( 1, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( true, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( false, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( null, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( void 0, x, 2, 0, isPositive, {} ); // $ExpectError + cueveryBy.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 containing numbers... +{ + const x = [ 1, 1, 0, 0, 0 ]; + + cueveryBy.assign( x, 1, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, true, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, false, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, null, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, void 0, 1, 0, isPositive ); // $ExpectError + cueveryBy.assign( x, {}, 1, 0, isPositive ); // $ExpectError + + cueveryBy.assign( x, 1, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, true, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, false, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, null, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, void 0, 1, 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, {}, 1, 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a valid index... +{ + const x = [ 1, 1, 0, 0, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cueveryBy.assign( x, y, '1', 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, true, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, false, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, null, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, void 0, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, {}, 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, [], 1, isPositive ); // $ExpectError + cueveryBy.assign( x, y, ( x: number ): number => x, 1, isPositive ); // $ExpectError + + cueveryBy.assign( x, y, '1', 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, true, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, false, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, null, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, void 0, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, {}, 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, [], 1, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, ( x: number ): number => x, 1, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const x = [ 1, 1, 0, 0, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cueveryBy.assign( x, y, 0, '1', isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, true, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, false, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, null, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, void 0, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, {}, isPositive ); // $ExpectError + cueveryBy.assign( x, y, 0, [], isPositive ); // $ExpectError + + cueveryBy.assign( x, y, 0, '1', isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, true, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, false, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, null, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, void 0, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, {}, isPositive, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, [], isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a function... +{ + const x = [ 1, 1, 0, 0, 0 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cueveryBy.assign( x, y, 0, 1, '1' ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, true ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, false ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, null ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, void 0 ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, [] ); // $ExpectError + + cueveryBy.assign( x, y, 0, 1, '1', {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, true, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, false, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, null, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, void 0, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, {}, {} ); // $ExpectError + cueveryBy.assign( x, y, 0, 1, [], {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cueveryBy.assign(); // $ExpectError + cueveryBy.assign( [] ); // $ExpectError + cueveryBy.assign( [], [] ); // $ExpectError + cueveryBy.assign( [], [], 'throw' ); // $ExpectError + cueveryBy.assign( [], [], 'throw', [] ); // $ExpectError + cueveryBy.assign( [], [], 'throw', [], 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/examples/index.js b/lib/node_modules/@stdlib/array/base/cuevery-by/examples/index.js new file mode 100644 index 000000000000..4f66c381674e --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/examples/index.js @@ -0,0 +1,34 @@ +/** +* @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 cueveryBy = require( './../lib' ); + +function fcn( value ) { + return ( value > 0 ); +} + +// Generate an array of random values: +var x = bernoulli( 10, 0.8 ); +console.log( x ); + +// Cumulatively tests whether every array element passes a test: +var y = cueveryBy( x, fcn ); +console.log( y ); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/lib/assign.js b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/assign.js new file mode 100644 index 000000000000..03504aafdfb1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/assign.js @@ -0,0 +1,178 @@ +/** +* @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 every array element in a provided array passes a test implemented by a predicate function. +* +* @private +* @param {Collection} x - input 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 +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 1, 1, 0, 0, 0 ]; +* +* var out = [ 0, 0, 0, 0, 0 ]; +* var arr = indexed( x, out, 1, 0, isPositive ); +* // returns [ true, true, false, false, false ] +*/ +function indexed( x, out, stride, offset, predicate, thisArg ) { + var flg; + var io; + var i; + + flg = true; + io = offset; + for ( i = 0; i <= x.length - 1; i++ ) { + if ( !flg ) { + out[ io ] = flg; + io += stride; + continue; + } + if ( !predicate.call( thisArg, x[ i ], i, x )) { + flg = false; + } + out[ io ] = flg; + io += stride; + } + return out; +} + +/** +* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. +* +* @private +* @param {Object} x - input array object +* @param {Object} out - 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' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = toAccessorArray( [ 1, 1, 0, 0, 0 ] ); +* +* var out = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); +* var arr = accessors( arraylike2object( x ), arraylike2object( out ), 1, 0, isPositive ); +* +* var v = arr.get( 4 ); +* // returns false +*/ +function accessors( x, out, stride, offset, predicate, thisArg ) { + var xdata; + var odata; + var xget; + var oset; + var flg; + var io; + var i; + + xdata = x.data; + odata = out.data; + + xget = x.accessors[ 0 ]; + oset = out.accessors[ 1 ]; + + io = offset; + flg = true; + for ( i = 0; i <= xdata.length - 1; i++ ) { + if ( !flg ) { + oset( odata, io, flg ); + io += stride; + continue; + } + if ( !predicate.call( thisArg, xget( xdata, i ), i, xdata ) ) { + flg = false; + } + oset( odata, io, flg ); + io += stride; + } + return odata; +} + + +// MAIN // + +/** +* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function. +* +* @param {Collection} x - input 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 +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 1, 1, 1, 0, 1 ]; +* +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* var out = assign( x, y, 2, 0, isPositive ); +* // returns [ true, null, true, null, true, null, false, null, false, null ] +* +* var bool = ( y === out ); +* // returns true +*/ +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/cuevery-by/lib/index.js b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/index.js new file mode 100644 index 000000000000..a294acf89c2a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/index.js @@ -0,0 +1,64 @@ +/** +* @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 every array element in a provided array passes a test implemented by a predicate function. +* +* @module @stdlib/array/base/cuevery-by +* +* @example +* var cueveryBy = require( '@stdlib/array/base/cuevery-by' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 1, 1, 1, 0, 1 ]; +* var y = cueveryBy( x, isPositive ); +* // returns [ true, true, true, false, false ] +* +* @example +* var cueveryBy = require( '@stdlib/array/base/cuevery-by' ); +* +* var x = [ 1, 1, 1, 0, 1 ]; +* +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* var out = cueveryBy.assign( x, y, 2, 0, isPositive ); +* // returns [ true, null, true, null, true, null, false, null, false, null ] +* +* var bool = ( arr === out ); +* // returns true +*/ + +// 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/cuevery-by/lib/main.js b/lib/node_modules/@stdlib/array/base/cuevery-by/lib/main.js new file mode 100644 index 000000000000..ec6598204bc3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-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 every array element in a provided array passes a test implemented by a predicate function. +* +* @param {Collection} x - input collection +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Array} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 1, 1, 1, 0, 1 ]; +* +* var y = cueveryBy( x, isPositive ); +* // returns [ true, true, true, false, false ] +*/ +function cueveryBy( x, predicate, thisArg ) { + var out = filled( false, x.length ); + return assign( x, out, 1, 0, predicate, thisArg ); +} + + +// EXPORTS // + +module.exports = cueveryBy; diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/package.json b/lib/node_modules/@stdlib/array/base/cuevery-by/package.json new file mode 100644 index 000000000000..d772df514dcd --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/cuevery-by", + "version": "0.0.0", + "description": "Cumulatively test whether every array 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", + "cuevery-by", + "cumulative", + "test", + "every", + "array.every", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.assign.js new file mode 100644 index 000000000000..b50c2831e589 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.assign.js @@ -0,0 +1,244 @@ +/** +* @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 Float64Array = require( '@stdlib/array/float64' ); +var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var cueveryBy = require( './../lib/assign.js' ); + + +// TESTS // + +function isPositive( v ) { + return ( v > 0 ); +} + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cueveryBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = [ 1, 1, 1, 0, 1 ]; + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cueveryBy( x, y, 2, 0, isPositive); + expected = [ true, null, true, null, true, null, false, null, false, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 1, 1, 0, 0 ]; + y = [ false, null, false, null, false, null, false, null ]; + + actual = cueveryBy( x, y, 2, 0, isPositive ); + expected = [ true, null, true, null, false, null, false, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0, 0, 1, 0, 1 ]; + y = [ false, false, false, true, true, true ]; + + actual = cueveryBy( x, y, 1, 1, isPositive ); + expected = [ false, false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = []; + y = [ false, false, false, false, false ]; + + actual = cueveryBy( 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' ); + + x = [ 1 ]; + y = [ false, false ]; + + actual = cueveryBy( x, y, 1, 1, isPositive ); + 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 every array element in a provided array passes a test implemented by a predicate function (typed)', function test( t ) { + var expected; + var actual; + var x; + var y; + + x = new Float64Array( [ 1.0, 2.0, 3.0, 4.0 ] ); + y = [ false, true, false, true, false ]; + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ true, true, true, true, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 0.0, 0.0 ] ); + y = [ false, null, false, null, false, null, false, null ]; + + actual = cueveryBy( x, y, 2, 0, isPositive ); + expected = [ true, null, true, null, false, null, false, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); + y = [ true, false, false, true, true, true ]; + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false, 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 = cueveryBy( 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' ); + + x = new Float64Array( [ 1.0 ] ); + y = [ false, false ]; + + actual = cueveryBy( x, y, 1, 1, isPositive ); + 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 every array element in a provided array passes a test implemented by a predicate function (accessor)', function test( t ) { + var expected; + var actual; + var ybuf; + var x; + var y; + + x = toAccessorArray( [ 1, 0, 0, 0, 1 ] ); + ybuf = [ false, true, false, true, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ true, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 1, 1, 0 ] ); + ybuf = [ false, null, false, null, false, null, false, null ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 2, 0, isPositive ); + expected = [ false, null, false, null, false, null, false, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 1, 1, 0, 0 ] ); + ybuf = [ true, false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 1, isPositive ); + expected = [ true, true, true, true, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 0, 0, 0, 1 ] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ true, false, false, false, false ]; + + 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 = cueveryBy( x, y, 1, 0, isPositive ); + expected = [ false, false, false, false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1 ] ); + ybuf = [ false, false ]; + y = toAccessorArray( ybuf ); + + actual = cueveryBy( x, y, 1, 1, isPositive ); + expected = [ false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var actual; + var ctx; + var x; + var y; + + ctx = { + 'count': 0 + }; + + x = [ 1, 1, 1, 0, 1 ]; + y = [ false, null, false, null, false, null, false, null, false, null ]; + + actual = cueveryBy( x, y, 2, 0, predicate, ctx); + expected = [ true, null, true, null, true, null, false, null, false, null ]; + + t.deepEqual( actual, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 4, 'returns expected value' ); + 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/cuevery-by/test/test.js b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.js new file mode 100644 index 000000000000..d49635ce2da6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-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 cueveryBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cueveryBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cueveryBy, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( cueveryBy, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.main.js new file mode 100644 index 000000000000..50069ba9b7b0 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cuevery-by/test/test.main.js @@ -0,0 +1,169 @@ +/** +* @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 toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cueveryBy = require( './../lib' ); + + +// TESTS // + +function isPositive( v ) { + return ( v > 0 ); +} + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual(typeof cueveryBy, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var x; + + function isNotNull( v ) { + return v !== null; + } + + x = [ 1, 2, 0, 4 ]; + + actual = cueveryBy( x, isPositive ); + expected = [true, true, false, false]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0.0, 0.0, 0.0, 1.0, 1.0 ]; + actual = cueveryBy( x, isPositive ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, true, true, true, true ]; + actual = cueveryBy( x, isPositive ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ {}, null, {} ]; + actual = cueveryBy( x, isNotNull ); + expected = [ true, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether every array 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( [ 1.0, 1.0, 1.0, 0.0, 1.0 ] ); + actual = cueveryBy( 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 = cueveryBy( 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 =cueveryBy( x, isPositive ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, 1.0, 0.0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ true, true, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 1.0, -2.0, 3.0, 0.0, 1.0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ true, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function (accessor array)', function test( t ) { + var expected; + var actual; + var x; + + x = toAccessorArray( [ 1, 1, 0, 0, 0 ] ); + + actual = cueveryBy( x, isPositive ); + expected = [true, true, false, false, false]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [false, false, false, false, false]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 1, 1, 1, 1 ] ); + actual = cueveryBy( x, isPositive ); + expected = [true, true, true, true, true]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 1, 0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); + actual = cueveryBy( x, isPositive ); + expected = [ true, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns an empty array if provided an empty input array as first argument', function test( t ) { + var x = []; + t.deepEqual( cueveryBy( x, isPositive ), [], 'returns expected value' ); + t.end(); +}); + +tape( 'the function supports providing an execution context', function test( t ) { + var expected; + var out; + var ctx; + var x; + + ctx = { + 'count': 0 + }; + + x = [ 1, 2, 0, 4 ]; + + out = cueveryBy( x, predicate, ctx ); + expected = [ true, true, false, false ]; + + t.deepEqual( out, expected, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( v > 0 ); + } +});