diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/README.md b/lib/node_modules/@stdlib/array/base/cunone-by/README.md new file mode 100644 index 000000000000..6edcf4850fed --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/README.md @@ -0,0 +1,56 @@ + +# cunone-by + +> Cumulatively test whether every element in a provided array passes a test implemented by a predicate function. + +## Usage + +```javascript +var cunoneBy = require( '@stdlib/array/base/cunone-by' ); + +cunoneBy( x, predicate ); + +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cunoneBy = require( '@stdlib/array/base/cunone-by' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.6 ); +console.log( x ); + +// Define a predicate function: +function predicate( v ) { + return v === 1; +} + +// Cumulatively determine whether values pass the predicate: +var out = cunoneBy( x, predicate ); +console.log( out ); + +In this example, out will contain an array of boolean values indicating whether each element in x equals 1. + +This module is part of the stdlib ecosystem, providing reliable and tested implementations for standard library functions in JavaScript. + + + + + + + \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.assign.length.js new file mode 100644 index 000000000000..9cb366d006cf --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.assign.length.js @@ -0,0 +1,98 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var cunoneBy = 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( true, len ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cunoneBy.assign( x, y, 1, 0 ); + 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(); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.js new file mode 100644 index 000000000000..d5fc78fbcb26 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.js @@ -0,0 +1,88 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var cunoneBy = require( './../lib' ); + + +// FUNCTIONS // + +function predicate( v ) { + return v === false; +} + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var x; + var i; + var v; + + x = [ false, false, true, false, false ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + v = cunoneBy( x, predicate ); + 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(); +}); + +bench( pkg+':assign', function benchmark( b ) { + var out; + var x; + var y; + var i; + + x = [ false, false, true, false, false ]; + out = [ 0, 0, 0, 0, 0 ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + y = cunoneBy.assign( x, out, 1, 0, predicate ); + if ( typeof y !== 'object' ) { + b.fail( 'should return an array' ); + } + } + b.toc(); + if ( !isArray( y ) || y !== out ) { + b.fail( 'should return the output array' ); + } + for ( i = 0; i < y.length; i++ ) { + if ( !isBoolean( y[i] ) ) { + b.fail( 'should only contain boolean values' ); + } + } + b.pass( 'benchmark finished' ); + b.end(); +}); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.length.js new file mode 100644 index 000000000000..1e0d618ac6ee --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/benchmark/benchmark.length.js @@ -0,0 +1,106 @@ +/** +* @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 pkg = require( './../package.json' ).name; +var cunoneBy = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Predicate function. +* +* @private +* @param {number} v - array element +* @returns {boolean} predicate result +*/ +function predicate( v ) { + return v < 1.0; +} + +/** +* 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 = cunoneBy( x, predicate ); + 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(); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cunone-by/docs/repl.txt new file mode 100644 index 000000000000..af6d6eb09c9b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/docs/repl.txt @@ -0,0 +1,52 @@ +{{alias}}( x, predicate ) + Cumulatively tests whether every element in a provided array fails a test implemented by a predicate function. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + predicate: Function + The predicate function to apply to each element. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > var x = [ 1, 2, 3, 4, 5 ]; + > var y = {{alias}}( x, function(v) { return v % 2 === 0; } ) + [ true, false, false, false, false ] + + +{{alias}}.assign( x, y, predicate, stride, offset ) + Cumulatively tests whether every element in an array fails a test implemented by a predicate function and assigns results to provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + y: ArrayLikeObject + Output array. + predicate: Function + The predicate function to apply to each element. + stride: integer + Output array stride. + offset: integer + Output array offset. + + Returns + ------- + y: ArrayLikeObject + Output array. + + Examples + -------- + > var x = [ 1, 2, 3, 4, 5 ]; + > var y = [ false, null, false, null, false, null, false, null, false ]; + > var result = {{alias}}.assign( x, y, function(v) { return v % 2 === 0; }, 2, 0 ) + [ true, null, false, null, false, null, false, null, false ] + + See Also + -------- \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cunone-by/docs/types/index.d.ts new file mode 100644 index 000000000000..4c6bd729ec97 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/docs/types/index.d.ts @@ -0,0 +1,100 @@ +/* +* @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 } from '@stdlib/types/array'; + +/** +* Predicate function. +* +* @param value - array element +* @returns boolean indicating whether the element satisfies the predicate +*/ +type Predicate = (value: T) => boolean; + +/** +* Interface describing `cunoneBy`. +*/ +interface CunoneBy { + /** + * Cumulatively tests whether every element in a provided array fails a test implemented by a predicate function. + * + * @param x - input array + * @param predicate - predicate function + * @returns output array + * + * @example + * var x = [ 1, 2, 3, 4, 5 ]; + * + * var y = cunoneBy( x, function isEven( v ) { return v % 2 === 0; } ); + * // returns [ true, false, false, false, false ] + */ + (x: Collection | AccessorArrayLike, predicate: Predicate): Array; + + /** + * Cumulatively tests whether every element in an array fails 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 predicate - predicate function + * @param stride - output array stride + * @param offset - output array offset + * @returns output array + * + * @example + * var x = [ 1, 2, 3, 4, 5 ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cunoneBy.assign( x, y, function isEven( v ) { return v % 2 === 0; }, 2, 0 ); + * // returns [ true, null, false, null, false, null, false, null, false, null ] + */ + assign | AccessorArrayLike>( + x: Collection | AccessorArrayLike, + y: U, + predicate: Predicate, + stride: number, + offset: number + ): U; +} + +/** +* Cumulatively tests whether every element in a provided array fails a test implemented by a predicate function. +* +* @param x - input array +* @param predicate - predicate function +* @returns output array +* +* @example +* var x = [ 1, 2, 3, 4, 5 ]; +* +* var result = cunoneBy( x, function isEven( v ) { return v % 2 === 0; } ); +* // returns [ true, false, false, false, false ] +* +* @example +* var x = [ 1, 2, 3, 4, 5 ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cunoneBy.assign( x, y, function isEven( v ) { return v % 2 === 0; }, 2, 0 ); +* // returns [ true, null, false, null, false, null, false, null, false, null ] +*/ +declare var cunoneBy: CunoneBy; + +export = cunoneBy; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cunone-by/docs/types/test.ts new file mode 100644 index 000000000000..a4be4244d971 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/docs/types/test.ts @@ -0,0 +1,141 @@ +/* +* @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 cunoneBy = require( './index' ); + +// TESTS // + +// The function returns an array... +{ + cunoneBy( [ 1, 2, 3, 4, 5 ], (x: number) => x > 10 ); // $ExpectType boolean[] + cunoneBy( [ 'a', 'b', 'c' ], (x: string) => x === 'd' ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + cunoneBy( 1, (x: any) => x > 0 ); // $ExpectError + cunoneBy( true, (x: any) => x === true ); // $ExpectError + cunoneBy( false, (x: any) => x === false ); // $ExpectError + cunoneBy( null, (x: any) => x === null ); // $ExpectError + cunoneBy( undefined, (x: any) => x === undefined ); // $ExpectError + cunoneBy( {}, (x: any) => typeof x === 'object' ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is not a function... +{ + cunoneBy( [1, 2, 3], 'not a function' ); // $ExpectError + cunoneBy( [1, 2, 3], 123 ); // $ExpectError + cunoneBy( [1, 2, 3], true ); // $ExpectError + cunoneBy( [1, 2, 3], false ); // $ExpectError + cunoneBy( [1, 2, 3], null ); // $ExpectError + cunoneBy( [1, 2, 3], undefined ); // $ExpectError + cunoneBy( [1, 2, 3], {} ); // $ExpectError + cunoneBy( [1, 2, 3], [] ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cunoneBy(); // $ExpectError + cunoneBy( [1, 2, 3] ); // $ExpectError + cunoneBy( [1, 2, 3], (x: number) => x > 0, {} ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ 1, 2, 3, 4, 5 ]; + const y = [ false, null, false, null, false, null, false, null, false, null ]; + + cunoneBy.assign( x, y, (v: number) => v > 10, 2, 0 ); // $ExpectType (boolean | null)[] +} + +// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object... +{ + const y = [ false, null, false, null, false ]; + + cunoneBy.assign( 1, y, (x: any) => x > 0, 2, 0 ); // $ExpectError + cunoneBy.assign( true, y, (x: any) => x === true, 2, 0 ); // $ExpectError + cunoneBy.assign( false, y, (x: any) => x === false, 2, 0 ); // $ExpectError + cunoneBy.assign( null, y, (x: any) => x === null, 2, 0 ); // $ExpectError + cunoneBy.assign( undefined, y, (x: any) => x === undefined, 2, 0 ); // $ExpectError + cunoneBy.assign( {}, y, (x: any) => typeof x === 'object', 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object... +{ + const x = [ 1, 2, 3, 4, 5 ]; + + cunoneBy.assign( x, 1, (v: number) => v > 0, 2, 0 ); // $ExpectError + cunoneBy.assign( x, true, (v: number) => v > 0, 2, 0 ); // $ExpectError + cunoneBy.assign( x, false, (v: number) => v > 0, 2, 0 ); // $ExpectError + cunoneBy.assign( x, null, (v: number) => v > 0, 2, 0 ); // $ExpectError + cunoneBy.assign( x, undefined, (v: number) => v > 0, 2, 0 ); // $ExpectError + cunoneBy.assign( x, {}, (v: number) => v > 0, 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not a function... +{ + const x = [ 1, 2, 3, 4, 5 ]; + const y = [ false, null, false, null, false ]; + + cunoneBy.assign( x, y, 'not a function', 2, 0 ); // $ExpectError + cunoneBy.assign( x, y, 123, 2, 0 ); // $ExpectError + cunoneBy.assign( x, y, true, 2, 0 ); // $ExpectError + cunoneBy.assign( x, y, false, 2, 0 ); // $ExpectError + cunoneBy.assign( x, y, null, 2, 0 ); // $ExpectError + cunoneBy.assign( x, y, undefined, 2, 0 ); // $ExpectError + cunoneBy.assign( x, y, {}, 2, 0 ); // $ExpectError + cunoneBy.assign( x, y, [], 2, 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number... +{ + const x = [ 1, 2, 3, 4, 5 ]; + const y = [ false, null, false, null, false ]; + + cunoneBy.assign( x, y, (v: number) => v > 0, '1', 0 ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, true, 0 ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, false, 0 ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, null, 0 ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, undefined, 0 ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, {}, 0 ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, [], 0 ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth argument which is not a number... +{ + const x = [ 1, 2, 3, 4, 5 ]; + const y = [ false, null, false, null, false ]; + + cunoneBy.assign( x, y, (v: number) => v > 0, 1, '1' ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, 1, true ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, 1, false ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, 1, null ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, 1, undefined ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, 1, {} ); // $ExpectError + cunoneBy.assign( x, y, (v: number) => v > 0, 1, [] ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cunoneBy.assign(); // $ExpectError + cunoneBy.assign( [] ); // $ExpectError + cunoneBy.assign( [], [] ); // $ExpectError + cunoneBy.assign( [], [], (x: any) => x > 0 ); // $ExpectError + cunoneBy.assign( [], [], (x: any) => x > 0, 1 ); // $ExpectError + cunoneBy.assign( [], [], (x: any) => x > 0, 1, 0, 10 ); // $ExpectError +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/examples/index.js b/lib/node_modules/@stdlib/array/base/cunone-by/examples/index.js new file mode 100644 index 000000000000..6214110f7fd6 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/examples/index.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'; + +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cunoneBy = require( './../lib' ); + +// Create an array of random values: +var x = bernoulli( 10, 0.5 ); +console.log( 'Input array:' ); +console.log( x ); + +// Define a predicate function: +function predicate( value ) { + return value === 1; +} + +// Cumulatively determine whether values are 1: +var out = cunoneBy( x, predicate ); +console.log( '\nOutput array (cumulative none equal to 1):' ); +console.log( out ); + +// Define another predicate function: +function isEven( value ) { + return value % 2 === 0; +} + +// Create an array of integers: +var y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; +console.log( '\nInput array:' ); +console.log( y ); + +// Cumulatively determine whether values are even: +out = cunoneBy( y, isEven ); +console.log( '\nOutput array (cumulative none even):' ); +console.log( out ); \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/lib/assign.js b/lib/node_modules/@stdlib/array/base/cunone-by/lib/assign.js new file mode 100644 index 000000000000..38a5d82dda47 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/lib/assign.js @@ -0,0 +1,58 @@ +'use strict'; + +// MODULES // + +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); +var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); + +// MAIN // + +/** + * Cumulatively tests whether no array elements pass a test implemented by a predicate function and assigns results to an output array. + * + * @param {Array|TypedArray} x - input array + * @param {Array|TypedArray} out - output array + * @param {integer} stride - output array stride + * @param {NonNegativeInteger} offset - output array index offset + * @param {Function} predicate - predicate function + * @returns {Array|TypedArray} output array + * + * @example + * function isPositive( value ) { + * return ( value > 0 ); + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * var out = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var y = assign( x, out, 2, 0, isPositive ); + * // returns [ true, null, true, null, true, null, false, null, false, null ] + */ +function assign( x, out, stride, offset, predicate ) { + var getter; + var prevResult; + var ix; + var i; + + if ( isAccessorArray( x ) ) { + getter = accessorGetter( x ); + } + + ix = offset; + prevResult = true; + + for ( i = 0; i < x.length; i++ ) { + if ( i === 0 ) { + prevResult = !predicate( getter ? getter( x, i ) : x[ i ] ); + } else { + prevResult = prevResult && !predicate( getter ? getter( x, i ) : x[ i ] ); + } + out[ ix ] = prevResult; + ix += stride; + } + return out; +} + +// EXPORTS // + +module.exports = assign; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/lib/index.js b/lib/node_modules/@stdlib/array/base/cunone-by/lib/index.js new file mode 100644 index 000000000000..1c8fa3b75fde --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/lib/index.js @@ -0,0 +1,46 @@ +'use strict'; + +/** + * Cumulatively test whether no array elements pass a test implemented by a predicate function. + * + * @module @stdlib/array/base/cunone-by + * + * @example + * var cunoneBy = require( '@stdlib/array/base/cunone-by' ); + * + * function isPositive( value ) { + * return ( value > 0 ); + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * + * var y = cunoneBy( x, isPositive ); + * // returns [ true, true, true, false, false ] + * + * @example + * var cunoneBy = require( '@stdlib/array/base/cunone-by' ); + * + * function isPositive( value ) { + * return ( value > 0 ); + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * var out = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var y = cunoneBy.assign( x, out, 2, 0, isPositive ); + * // returns [ true, null, true, null, true, null, false, null, false, 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; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/lib/main.js b/lib/node_modules/@stdlib/array/base/cunone-by/lib/main.js new file mode 100644 index 000000000000..88803b403724 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/lib/main.js @@ -0,0 +1,50 @@ +'use strict'; + +// MODULES // + +var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); +var accessorGetter = require( '@stdlib/array/base/accessor-getter' ); + +// MAIN // + +/** + * Cumulatively tests whether no array elements pass a test implemented by a predicate function. + * + * @param {Array|TypedArray} x - input array + * @param {Function} predicate - predicate function + * @returns {Array} output array + * + * @example + * function isPositive( value ) { + * return ( value > 0 ); + * } + * + * var x = [ 0, 0, 0, 1, 0 ]; + * + * var y = cunoneBy( x, isPositive ); + * // returns [ true, true, true, false, false ] + */ +function cunoneBy( x, predicate ) { + var getter; + var out; + var i; + + if ( isAccessorArray( x ) ) { + getter = accessorGetter( x ); + } + + out = new Array( x.length ); + + for ( i = 0; i < x.length; i++ ) { + if ( i === 0 ) { + out[ i ] = !predicate( getter ? getter( x, i ) : x[ i ] ); + } else { + out[ i ] = out[ i - 1 ] && !predicate( getter ? getter( x, i ) : x[ i ] ); + } + } + return out; +} + +// EXPORTS // + +module.exports = cunoneBy; \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/package.json b/lib/node_modules/@stdlib/array/base/cunone-by/package.json new file mode 100644 index 000000000000..d48ab559fa69 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/package.json @@ -0,0 +1,89 @@ +{ + "name": "@stdlib/array/base/cunone-by", + "version": "0.0.0", + "description": "Cumulatively test whether no array elements pass 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": { + "test": "make test", + "test-cov": "make test-cov", + "examples": "make examples", + "benchmark": "make benchmark" + }, + "homepage": "https://stdlib.io", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/array-base-cunone-by.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": { + "@stdlib/array-base-assert-is-accessor-array": "^0.0.x", + "@stdlib/array-base-accessor-getter": "^0.0.x", + "@stdlib/types": "^0.0.x", + "@stdlib/utils-define-nonenumerable-read-only-property": "^0.0.x" + }, + "devDependencies": { + "@stdlib/array-float64": "^0.0.x", + "@stdlib/assert-is-boolean-array": "^0.0.x", + "@stdlib/math-base-assert-is-nan": "^0.0.x", + "tape": "git+https://github.com/kgryte/tape.git#fix/globby", + "istanbul": "^0.4.1", + "tap-min": "git+https://github.com/Planeshifter/tap-min.git" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdarray", + "base", + "array", + "cumulative", + "none", + "noneby", + "test", + "predicate", + "function", + "array.none", + "every", + "all", + "validate" + ], + "__stdlib__": {}, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/stdlib" + } +} \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cunone-by/test/test.assign.js new file mode 100644 index 000000000000..d0d56b740b14 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/test/test.assign.js @@ -0,0 +1,130 @@ +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cunoneBy = require( './../lib' ); + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cunoneBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether no array elements pass a test', function test( t ) { + var expected; + var actual; + var x; + + x = [ 0, 0, 0, 1, 0 ]; + + expected = [ true, true, true, false, false ]; + actual = cunoneBy( x, isPositive ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function supports typed arrays', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array([ 0.0, 0.0, 0.0, 1.0, 0.0 ]); + + expected = [ true, true, true, false, false ]; + actual = cunoneBy( x, isPositive ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function supports accessor arrays', function test( t ) { + var expected; + var actual; + var x; + + x = { + 'length': 5, + '0': 0, + '1': 0, + '2': 0, + '3': 1, + '4': 0, + 'get': getter + }; + + expected = [ true, true, true, false, false ]; + actual = cunoneBy( x, isPositive ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } + + function getter( idx ) { + return this[ idx ]; + } +}); + +tape( 'the function handles empty arrays', function test( t ) { + var actual = cunoneBy( [], isPositive ); + t.deepEqual( actual, [], 'returns an empty array' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function handles arrays with all elements passing the test', function test( t ) { + var x = [ 1, 2, 3, 4, 5 ]; + var expected = [ false, false, false, false, false ]; + var actual = cunoneBy( x, isPositive ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function handles arrays with all elements failing the test', function test( t ) { + var x = [ -1, -2, -3, -4, -5 ]; + var expected = [ true, true, true, true, true ]; + var actual = cunoneBy( x, isPositive ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function correctly handles NaN values', function test( t ) { + var x = [ 0, NaN, 0, 1, 0 ]; + var expected = [ true, false, false, false, false ]; + var actual = cunoneBy( x, isPositive ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +// Add more tests as needed \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/test/test.js b/lib/node_modules/@stdlib/array/base/cunone-by/test/test.js new file mode 100644 index 000000000000..bb48478fa502 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/test/test.js @@ -0,0 +1,108 @@ +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var cunoneBy = require( './../lib' ); + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cunoneBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an assign method', function test( t ) { + t.strictEqual( typeof cunoneBy.assign, 'function', 'has assign method' ); + t.end(); +}); + +tape( 'the function throws an error if provided a first argument which is not an array-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cunoneBy( value, function() {} ); + }; + } +}); + +tape( 'the function throws an error if provided a second argument which is not a function', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + {}, + [] + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cunoneBy( [1, 2, 3], value ); + }; + } +}); + +tape( 'the function returns an array', function test( t ) { + var out = cunoneBy( [1, 2, 3], function() { return true; } ); + t.strictEqual( Array.isArray(out), true, 'returns an array' ); + t.end(); +}); + +tape( 'the assign method throws an error if provided a first argument which is not an array-like object', function test( t ) { + var values; + var i; + + values = [ + '5', + 5, + true, + false, + null, + void 0, + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + cunoneBy.assign( value, [], 1, 0, function() {} ); + }; + } +}); + +// Add more tests as needed for the assign method and other aspects of the main export \ No newline at end of file diff --git a/lib/node_modules/@stdlib/array/base/cunone-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cunone-by/test/test.main.js new file mode 100644 index 000000000000..8e0477d5bd3d --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cunone-by/test/test.main.js @@ -0,0 +1,158 @@ +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var Float64Array = require( '@stdlib/array/float64' ); +var cunoneBy = require( './../lib' ); + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cunoneBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether no array elements pass a test', function test( t ) { + var expected; + var actual; + var x; + + x = [ 0, 0, 0, 1, 0 ]; + + expected = [ true, true, true, false, false ]; + actual = cunoneBy( x, isPositive ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function supports typed arrays', function test( t ) { + var expected; + var actual; + var x; + + x = new Float64Array([ 0.0, 0.0, 0.0, 1.0, 0.0 ]); + + expected = [ true, true, true, false, false ]; + actual = cunoneBy( x, isPositive ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function supports accessor arrays', function test( t ) { + var expected; + var actual; + var x; + + x = { + 'length': 5, + '0': 0, + '1': 0, + '2': 0, + '3': 1, + '4': 0, + 'get': getter + }; + + expected = [ true, true, true, false, false ]; + actual = cunoneBy( x, isPositive ); + + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } + + function getter( idx ) { + return this[ idx ]; + } +}); + +tape( 'the function handles empty arrays', function test( t ) { + var actual = cunoneBy( [], isPositive ); + t.deepEqual( actual, [], 'returns an empty array' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function handles arrays with all elements passing the test', function test( t ) { + var x = [ 1, 2, 3, 4, 5 ]; + var expected = [ false, false, false, false, false ]; + var actual = cunoneBy( x, isPositive ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function handles arrays with all elements failing the test', function test( t ) { + var x = [ -1, -2, -3, -4, -5 ]; + var expected = [ true, true, true, true, true ]; + var actual = cunoneBy( x, isPositive ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function correctly handles NaN values', function test( t ) { + var x = [ 0, NaN, 0, 1, 0 ]; + var expected = [ true, false, false, false, false ]; + var actual = cunoneBy( x, isPositive ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isPositive( value ) { + return value > 0; + } +}); + +tape( 'the function correctly handles custom predicates', function test( t ) { + var x = [ 'a', 'b', 'c', 'd', 'e' ]; + var expected = [ true, true, false, false, false ]; + var actual = cunoneBy( x, isVowel ); + t.deepEqual( actual, expected, 'returns expected value' ); + t.end(); + + function isVowel( char ) { + return ['a', 'e', 'i', 'o', 'u'].indexOf(char.toLowerCase()) !== -1; + } +}); + +tape( 'the function provides correct indices to the predicate function', function test( t ) { + var expected; + var actual; + var x; + + x = [ 1, 2, 3, 4, 5 ]; + expected = [ 0, 1, 2, 3, 4 ]; + actual = []; + + cunoneBy( x, function(value, index) { + actual.push(index); + return false; + }); + + t.deepEqual( actual, expected, 'provides correct indices' ); + t.end(); +}); \ No newline at end of file