From 96c2e87e08ed834335179209ffab7f405e0f20ab Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Thu, 26 Sep 2024 20:08:07 +0530 Subject: [PATCH 1/5] feat: add lib code for cusome-by # 2326 --- .../array/base/cusome-by/lib/assign.js | 176 ++++++++++++++++++ .../@stdlib/array/base/cusome-by/lib/index.js | 64 +++++++ .../@stdlib/array/base/cusome-by/lib/main.js | 56 ++++++ 3 files changed, 296 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/lib/assign.js create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/lib/index.js create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/lib/main.js diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/lib/assign.js b/lib/node_modules/@stdlib/array/base/cusome-by/lib/assign.js new file mode 100644 index 000000000000..647965093a18 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-by/lib/assign.js @@ -0,0 +1,176 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); + + +// FUNCTIONS // + +/** +* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* +* @private +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @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 = [ false, false, false, true, true ]; +* +* var out = [ false, null, false, null, false, null, false, null, false, null ]; +* var arr = indexed( x, 2, out, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, false, null, true, null ] +*/ +function indexed( x, n, out, stride, offset, predicate, thisArg ) { + var flg; + var io; + var i; + + flg = false; + io = offset; + for ( i = 0; i <= x.length - 1; i++ ) { + if ( !flg && predicate.call( thisArg, x[ i ], i, x ) ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + out[ io ] = flg; + io += stride; + } + return out; +} + +/** +* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* @private +* @param {Object} x - input array object +* @param {integer} n - number of elements +* @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( [ false, false, false, true, true ] ); +* +* var out = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); +* var arr = accessors( arraylike2object( x ), 2, arraylike2object( out ), 2, 0, isPositive ); +* +* var v = arr.get( 8 ); +* // returns true +*/ +function accessors( x, n, 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 = false; + for ( i = 0; i <= xdata.length - 1; i++ ) { + if ( !flg && predicate.call( thisArg, xget( xdata, i ), i, xdata ) ) { + n -= 1; + if ( n <= 0 ) { + flg = true; + } + } + + oset( odata, io, flg ); + io += stride; + } + return odata; +} + + +// MAIN // + +/** +* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* @param {Collection} x - input array +* @param {integer} n - number of elements +* @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 = [ false, false, false, true, true ]; +* +* var out = [ false, null, false, null, false, null, false, null, false, null ]; +* var arr = indexed( x, 2, out, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, false, null, true, null ] +* +* var bool = ( arr === out ); +* // returns true +*/ +function assign( x, n, out, stride, offset, predicate, thisArg ) { + var xo; + var oo; + + xo = arraylike2object( x ); + oo = arraylike2object( out ); + if ( xo.accessorProtocol || oo.accessorProtocol ) { + accessors( xo, n, oo, stride, offset, predicate, thisArg ); + return out; + } + indexed( x, n, out, stride, offset, predicate, thisArg ); + return out; +} + + +// EXPORTS // + +module.exports = assign; diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/lib/index.js b/lib/node_modules/@stdlib/array/base/cusome-by/lib/index.js new file mode 100644 index 000000000000..9cbcf399e68c --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-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 tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* +* @module @stdlib/array/base/cusome-by +* +* @example +* var cusomeBy = require( '@stdlib/array/base/cusome-by' ); +* +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 0, 0, 1, 1 ]; +* var y = cusomeBy( x, 2, isPositive ); +* // returns [ false, false, false, false, true ] +* +* @example +* var cusomeBy = require( '@stdlib/array/base/cusome-by' ); +* +* var x = [ 0, 0, 0, 1, 1 ]; +* +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* var out = cusomeBy.assign( x, 2, y, 2, 0, isPositive ); +* // returns [ false, null, false, null, false, null, false, null, true, null ]; +* +* var bool = ( y === 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/cusome-by/lib/main.js b/lib/node_modules/@stdlib/array/base/cusome-by/lib/main.js new file mode 100644 index 000000000000..f39660eff382 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-by/lib/main.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2024 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var filled = require( '@stdlib/array/base/filled' ); +var assign = require( './assign.js' ); + + +// MAIN // + +/** +* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* +* @param {Collection} x - input collection +* @param {integer} n - number of elements +* @param {Function} predicate - test function +* @param {*} [thisArg] - execution context +* @returns {Array} output array +* +* @example +* function isPositive( value ) { +* return ( value > 0 ); +* } +* +* var x = [ 0, 0, 0, 1, 1 ]; +* +* var y = cusomeBy( x, 2, isPositive ); +* // returns [ false, false, false, false, true ] +*/ +function cusomeBy( x, n, predicate, thisArg ) { + var out = filled( false, x.length ); + return assign( x, n, out, 1, 0, predicate, thisArg ); +} + + +// EXPORTS // + +module.exports = cusomeBy; From ed7b92bb50bb819046eca6867a42aa14c6fe1b68 Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Thu, 26 Sep 2024 22:54:23 +0530 Subject: [PATCH 2/5] feat: add docs and examples --- .../array/base/cusome-by/docs/repl.txt | 83 +++++++ .../base/cusome-by/docs/types/index.d.ts | 205 +++++++++++++++ .../array/base/cusome-by/docs/types/test.ts | 234 ++++++++++++++++++ .../array/base/cusome-by/examples/index.js | 34 +++ 4 files changed, 556 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/examples/index.js diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cusome-by/docs/repl.txt new file mode 100644 index 000000000000..fc9d3037c901 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-by/docs/repl.txt @@ -0,0 +1,83 @@ + +{{alias}}( x, n, predicate[, thisArg] ) + Cumulatively tests whether at least n array elements 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. + + n: integer + Number of elements. + + predicate: Function + Predicate function. + + thisArg: any (optional) + Execution context. + + Returns + ------- + out: Array + Output array. + + Examples + -------- + > function fcn( v ) { return ( v > 0 ); }; + > var x = [ 0, 0, 0, 1, 1 ]; + > var y = {{alias}}( x, 2, fcn ) + [ false, false, false, false, true ] + + +{{alias}}.assign( x, n, out, stride, offset, predicate[, thisArg] ) + Cumulatively tests whether at least n elements in a provided array pass a + test implemented by a predicate function and assigns the values to elements + in a provided output array. + + Parameters + ---------- + x: ArrayLikeObject + Input array. + + n: Integer + Number of Elements. + + 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 = [ 0, 0, 1, 1 ]; + > var out = [ false, null, false, null, false, null, false, null ]; + > var arr = {{alias}}.assign( x, 2, out, 2, 0, fcn ) + [ false, null, false, null, false, null, true, null ]; + > var bool = ( arr === out ) + true + + See Also + -------- diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/index.d.ts new file mode 100644 index 000000000000..6e540ceab1b4 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/index.d.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. +*/ + +// 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 `cusomeBy`. +*/ +interface CuSomeBy { + /** + * Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. + * + * @param x - input array + * @param n - number of elements + * @param predicate - test function + * @param thisArg - execution context + * @returns output array + * + * @example + * function isPositive( v ) { + * return ( v > 0 ); + * } + * var x = [ 0, 0, 0, 1, 1 ]; + * + * var y = cusomeBy( x, 2, isPositive ); + * // returns [ false, false, false, false, true, ]; + */ + ( x: Collection | AccessorArrayLike, n: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether aleast n array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. + * + * @param x - input array + * @param n - number of elements + * @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 = [ 0, 0, 0, 1, 1,]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cusomeBy.assign( x, 2, y, 2, 0, isPositive );, + * // returns [ false, null, false, null, false, null, false, null, true, null ]; + */ + assign( x: Collection | AccessorArrayLike, n: number, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; + + /** + * Cumulatively tests whether atlest n array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. + * + * @param x - input array + * @param n - number of elements + * @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, 1 ]; + * var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] ); + * + * var arr = cusomeBy.assign( x, 2, y, 2, 0, isPositive ); + * // returns + * + * var v = arr.get( 8 ); + * // returns true + */ + assign( x: Collection | AccessorArrayLike, n: number, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; + + /** + * Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. + * + * @param x - input array + * @param n - number of elements + * @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 = [ 0, 0, 0, 1, 1 ]; + * var y = [ false, null, false, null, false, null, false, null, false, null ]; + * + * var arr = cusomeBy.assign( x, 2, y, 2, 0, isPositive );, + * // returns [ false, null, false, null, false, null, false, null, true, null ]; + */ + assign( x: Collection | AccessorArrayLike, n: number, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; + +} + +/** +* Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function. +* +* @param x - input array +* @param n - number of elements +* @param predicate - test function +* @param thisArg - execution context +* @returns output array +* +* @example +* function isPositive( v ) { +* return ( v > 0 ); +* } +* var x = [ 0, 0, 0, 1, 1 ]; +* +* var result = cusomeBy( x, 2, isPositive ); +* // returns [ false, false, false, false, true ] +* +* @example +* function isPositive( v ) { +* return ( v > 0 ); +* } +* var x = [ 0, 0, 0, 1, 1 ]; +* var y = [ false, null, false, null, false, null, false, null, false, null ]; +* +* var arr = cusomeBy.assign( x, 2, y, 2, 0, isPositive ); +* //returns [ false, null, false, null, false, null, false, null, true, null ]; +*/ +declare var cusomeBy: CuSomeBy; + + +// EXPORTS // + +export = cusomeBy; diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/test.ts b/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/test.ts new file mode 100644 index 000000000000..0320b68d02e7 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/test.ts @@ -0,0 +1,234 @@ +/* +* @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 cusomeBy = require( './index' ); + +const isPositive = ( v: number ): boolean => { + return ( v > 0 ); +}; + + +// TESTS // + +// The function returns an array... +{ + cusomeBy( [ 1, 2, 3, 4 ], 2, isPositive ); // $ExpectType boolean[] + cusomeBy( [ 1, 2, 3, 4 ], 2, isPositive ); // $ExpectType boolean[] + + cusomeBy( [ 1, 2, 3, 4 ], 2, isPositive, {} ); // $ExpectType boolean[] + cusomeBy( [ 1, 2, 3, 4 ], 2, isPositive, {} ); // $ExpectType boolean[] +} + +// The compiler throws an error if the function is provided a first argument which is not an array-like object... +{ + cusomeBy( 1, 2, isPositive ); // $ExpectError + cusomeBy( true, 2, isPositive ); // $ExpectError + cusomeBy( false, 2, isPositive ); // $ExpectError + cusomeBy( null, 2, isPositive ); // $ExpectError + cusomeBy( void 0, 2, isPositive ); // $ExpectError + cusomeBy( {}, 2, isPositive ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument which is a number... +{ + cusomeBy( [], true, isPositive ); // $ExpectError + cusomeBy( [], false, isPositive ); // $ExpectError + cusomeBy( [], null, isPositive ); // $ExpectError + cusomeBy( [], void 0, isPositive ); // $ExpectError + cusomeBy( [], {}, isPositive ); // $ExpectError + cusomeBy( [], undefined, isPositive ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument which is not an array-like object containing numbers... +{ + cusomeBy( [], 2, 1 ); // $ExpectError + cusomeBy( [], 2, true ); // $ExpectError + cusomeBy( [], 2, false ); // $ExpectError + cusomeBy( [], 2, null ); // $ExpectError + cusomeBy( [], 2, void 0 ); // $ExpectError + cusomeBy( [], 2, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + cusomeBy(); // $ExpectError + cusomeBy( [] ); // $ExpectError + cusomeBy( [], 2, 'throw', {} , null ); // $ExpectError +} + +// Attached to the main export is an `assign` method which returns a collection... +{ + const x = [ 1, 2, 3, 4 ]; + + cusomeBy.assign( x, 2, [ 0, 0, 0, 0 ], 1, 0, isPositive ); // $ExpectType (number | boolean)[] + cusomeBy.assign( x, 2, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array + cusomeBy.assign( x, 2, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array + cusomeBy.assign( x, 2, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array + cusomeBy.assign( x, 2, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array + cusomeBy.assign( x, 2, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array + cusomeBy.assign( x, 2, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array + cusomeBy.assign( x, 2, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array + cusomeBy.assign( x, 2, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array + cusomeBy.assign( x, 2, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray + + cusomeBy.assign( x, 2, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[] + cusomeBy.assign( x, 2, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array + cusomeBy.assign( x, 2, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array + cusomeBy.assign( x, 2, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array + cusomeBy.assign( x, 2, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array + cusomeBy.assign( x, 2, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array + cusomeBy.assign( x, 2, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array + cusomeBy.assign( x, 2, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array + cusomeBy.assign( x, 2, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array + cusomeBy.assign( x, 2, 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 ]; + + cusomeBy.assign( 1, 2, x, 2, 0, isPositive ); // $ExpectError + cusomeBy.assign( true, 2, x, 2, 0, isPositive ); // $ExpectError + cusomeBy.assign( false, 2, x, 2, 0, isPositive ); // $ExpectError + cusomeBy.assign( null, 2, x, 2, 0, isPositive ); // $ExpectError + cusomeBy.assign( void 0, 2, x, 2, 0, isPositive ); // $ExpectError + cusomeBy.assign( {}, 2, x, 2, 0, isPositive ); // $ExpectError + + cusomeBy.assign( 1, 2, x, 2, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( true, 2, x, 2, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( false, 2, x, 2, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( null, 2, x, 2, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( void 0, 2, x, 2, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( {}, 2, x, 2, 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a second argument which is not a number.. +{ + const x = [ 1, 1, 0, 0, 0 ]; + + cusomeBy.assign( x, [], x, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, true, x, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, false, x, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, null, x, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, void 0, x, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, {}, x, 1, 0, isPositive ); // $ExpectError + + cusomeBy.assign( x, [], x, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, true, x, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, false, x, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, null, x, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, void 0, x, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, {}, x, 1, 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a third argument which is not an array-like object containing numbers... +{ + const x = [ 1, 1, 0, 0, 0 ]; + + cusomeBy.assign( x, 2, 1, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, true, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, false, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, null, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, void 0, 1, 0, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, {}, 1, 0, isPositive ); // $ExpectError + + cusomeBy.assign( x, 2, 1, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, true, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, false, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, null, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, void 0, 1, 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, {}, 1, 0, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fourth 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 ]; + + cusomeBy.assign( x, 2, y, '1', 1, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, true, 1, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, false, 1, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, null, 1, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, void 0, 1, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, {}, 1, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, [], 1, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, ( x: number ): number => x, 1, isPositive ); // $ExpectError + + cusomeBy.assign( x, 2, y, '1', 1, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, true, 1, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, false, 1, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, null, 1, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, void 0, 1, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, {}, 1, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, [], 1, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, ( x: number ): number => x, 1, isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a fifth 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 ]; + + cusomeBy.assign( x, 2, y, 0, '1', isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, true, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, false, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, null, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, void 0, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, {}, isPositive ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, [], isPositive ); // $ExpectError + + cusomeBy.assign( x, 2, y, 0, '1', isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, true, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, false, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, null, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, void 0, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, {}, isPositive, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, [], isPositive, {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided a sixth 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 ]; + + cusomeBy.assign( x, 2, y, 0, 1, '1' ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, true ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, false ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, null ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, void 0 ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, [] ); // $ExpectError + + cusomeBy.assign( x, 2, y, 0, 1, '1', {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, true, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, false, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, null, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, void 0, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, {}, {} ); // $ExpectError + cusomeBy.assign( x, 2, y, 0, 1, [], {} ); // $ExpectError +} + +// The compiler throws an error if the `assign` method is provided an unsupported number of arguments... +{ + cusomeBy.assign(); // $ExpectError + cusomeBy.assign( [] ); // $ExpectError + cusomeBy.assign( [], [] ); // $ExpectError + cusomeBy.assign( [], [], 'throw' ); // $ExpectError + cusomeBy.assign( [], [], 'throw', [] ); // $ExpectError + cusomeBy.assign( [], [], [], 'throw', [], 1, 0, {} ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/examples/index.js b/lib/node_modules/@stdlib/array/base/cusome-by/examples/index.js new file mode 100644 index 000000000000..8d44c323ade9 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-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 cusomeBy = 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 at least 3 array elements in a provided array passes a test implemented by a predicate function. +var y = cusomeBy( x, 3, fcn ); +console.log( y ); From 34e3d1b378d2f8da7057dd3212f33a4910ff4fa2 Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Fri, 27 Sep 2024 01:30:38 +0530 Subject: [PATCH 3/5] feat: add cusome-by --- .../@stdlib/array/base/cusome-by/README.md | 145 +++++++++++ .../benchmark/benchmark.assign.length.js | 99 +++++++ .../base/cusome-by/benchmark/benchmark.js | 53 ++++ .../cusome-by/benchmark/benchmark.length.js | 96 +++++++ .../@stdlib/array/base/cusome-by/package.json | 67 +++++ .../array/base/cusome-by/test/test.assign.js | 244 ++++++++++++++++++ .../@stdlib/array/base/cusome-by/test/test.js | 41 +++ .../array/base/cusome-by/test/test.main.js | 156 +++++++++++ 8 files changed, 901 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/README.md create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.assign.length.js create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.length.js create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/package.json create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/test/test.assign.js create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/test/test.js create mode 100644 lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/README.md b/lib/node_modules/@stdlib/array/base/cusome-by/README.md new file mode 100644 index 000000000000..9ee64e64ee7a --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-by/README.md @@ -0,0 +1,145 @@ + + +# cusomeBy + +> Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function. + +
+ +## Usage + +```javascript +var cusomeBy = require( '@stdlib/array/base/cusome-by' ); +``` + +#### cusomeBy( x, n, predicate\[, thisArg ] ) + +Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function. + +```javascript +function fcn( value) { + return ( value > 0 ); +} + +var x = [ 0, 0, 0, 1, 1 ]; + +var y = cusomeBy( x, 2, fcn ); +// returns [ false, false, false , false, true ] +``` + +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 = [ 0, 0, 0, 1, 1 ]; + +var context = { + 'count': 0 +}; + +var bool = cusomeBy( x, 1, fcn, context ); +// returns [ false, false, false, true, true ] + +var count = context.count; +// returns 4 +``` + +#### cusomeBy.assign( x, n, out, stride, offset, predicate\[, thisArg ] ) + +Cumulatively tests whether atleast n array elements in a provided array pass 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 = [ 0, 0, 0, 1, 1 ]; +var y = [ false, null, false, null, false, null, false, null, false, null ]; + +var out = cusomeBy.assign( x, 2, y, 2, 0, fcn ); +// returns [ false, null, false, null, false, null, false, null, true, null ] + +var bool = ( out === y ); +// returns true +``` + +
+ + + +
+ +
+ + + +
+ +## Examples + + + +```javascript +var bernoulli = require( '@stdlib/random/array/bernoulli' ); +var cusomeBy = require( '@stdlib/array/base/cusome-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 at least n array elements pass a test: +var y = cusomeBy( x, 2, fcn ); +console.log( y ); +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.assign.length.js b/lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.assign.length.js new file mode 100644 index 000000000000..f69c802a58f8 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-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 cusomeBy = 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 = cusomeBy.assign( x, 2, 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/cusome-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.js new file mode 100644 index 000000000000..954f51ef2349 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-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 cusomeBy = 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 = cusomeBy( x, 2, 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/cusome-by/benchmark/benchmark.length.js b/lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.length.js new file mode 100644 index 000000000000..4ea48252860f --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-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 cusomeBy = 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 = cusomeBy( x, 2, 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/cusome-by/package.json b/lib/node_modules/@stdlib/array/base/cusome-by/package.json new file mode 100644 index 000000000000..3694411308f1 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-by/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/array/base/cusome-by", + "version": "0.0.0", + "description": "Cumulatively test whether at least n array elements in a provided array 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": {}, + "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", + "cusome-by", + "cumulative", + "test", + "every", + "array.every", + "validate" + ] +} diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.assign.js new file mode 100644 index 000000000000..c9671ac0d07e --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-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 cusomeBy = 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 cusomeBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least n array elements in a provided array pass 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 = cusomeBy( x, 3, y, 2, 0, isPositive); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 1, 1, 0, 0 ]; + y = [ false, null, false, null, false, null, false, null ]; + + actual = cusomeBy( x, 3, y, 2, 0, isPositive ); + expected = [ false, null, false, 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 = cusomeBy( x, 1, y, 1, 1, isPositive ); + expected = [ false, false, false, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = []; + y = [ false, false, false, false, false ]; + + actual = cusomeBy( x, 2, 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 = cusomeBy( x, 1, 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 at least n array elements in a provided array pass 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 = cusomeBy( x, 3, y, 1, 0, isPositive ); + expected = [ false, false, 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 = cusomeBy( x, 2, y, 2, 0, isPositive ); + expected = [ false, null, true, null, true, null, true, null ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 1.0, 1.0, 0.0, 0.0 ] ); + y = [ true, false, false, true, true, true ]; + + actual = cusomeBy( x, 2, y, 1, 0, isPositive ); + expected = [ false, false, true, true, true, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [] ); + y = [ false, false, false, false, false ]; + + actual = cusomeBy( x, 1, 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 = cusomeBy( x, 3, y, 1, 1, isPositive ); + expected = [ false, false ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least n array elements in a provided array pass 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 = cusomeBy( x, 2, y, 1, 0, isPositive ); + expected = [ false, false, false, false, true ]; + + 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 = cusomeBy( x, 1, y, 2, 0, isPositive ); + expected = [ false, null, true, null, true, null, true, 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 = cusomeBy( x, 2, y, 1, 1, isPositive ); + expected = [ true, false, true, true, true, true ]; + + 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 = cusomeBy( x, 2, y, 1, 0, isPositive ); + expected = [ false, false, false, false, true ]; + + t.strictEqual( actual, y, 'returns expected value' ); + t.deepEqual( ybuf, expected, 'returns expected value' ); + + x = toAccessorArray( [] ); + ybuf = [ false, false, false, false, false ]; + y = toAccessorArray( ybuf ); + + actual = cusomeBy( x, 0, 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 = cusomeBy( x, 1, 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 = cusomeBy( x, 3, y, 2, 0, predicate, ctx); + expected = [ false, null, false, null, true, null, true, null, true, null ]; + + t.deepEqual( actual, 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 ); + } +}); diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.js b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.js new file mode 100644 index 000000000000..ae402bfb8f69 --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-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 cusomeBy = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof cusomeBy, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the main export is an `assign` method', function test( t ) { + t.strictEqual( hasOwnProp( cusomeBy, 'assign' ), true, 'returns expected value' ); + t.strictEqual( hasMethod( cusomeBy, 'assign' ), true, 'returns expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js new file mode 100644 index 000000000000..ac055542d32b --- /dev/null +++ b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js @@ -0,0 +1,156 @@ +/** +* @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 cusomeBy = 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 cusomeBy, 'function', 'main export is a function'); + t.end(); +}); + +tape( 'the function cumulatively tests whether at least n elements in a provided array pass a test implemented by a predicate function (generic)', function test( t ) { + var expected; + var actual; + var x; + + x = [ 0, 0, 0, 1, 1 ]; + + actual = cusomeBy( x, 2, isPositive ); + expected = [ false, false, false, false, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 0.0, 0.0, 0.0, 1.0, 1.0 ]; + actual = cusomeBy( x, 1, isPositive ); + expected = [ false, false, false, true, true]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ true, true, true, true, true ]; + actual = cusomeBy( x, 3, isPositive ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = [ 1, null, 1 ]; + actual = cusomeBy( x, 2, isPositive ); + expected = [ false, false, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least n elements in a provided array pass 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 = cusomeBy( x, 3, isPositive ); + expected = [ false, false, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] ); + actual = cusomeBy( x, 2, 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 =cusomeBy( x, 1, isPositive ); + expected = [ true, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function cumulatively tests whether at least n elements in a provided array pass 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 = cusomeBy( x, 2, isPositive ); + expected = [ false, true, true, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 0, 0, 0, 0 ] ); + actual = cusomeBy( x, 2, isPositive ); + expected = [ false, false, false, false, false ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 1, 1, 1, 1 ] ); + actual = cusomeBy( x, 4, isPositive ); + expected = [ false, false, false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 0, 1, 0 ] ); + actual = cusomeBy( x, 1, isPositive ); + expected = [ false, true, true ]; + t.deepEqual( actual, expected, 'returns expected value' ); + + x = toAccessorArray( [ 1, 0, 0, 0, 0 ] ); + actual = cusomeBy( x, 0, isPositive ); + expected = [ true, true, true, true, true ]; + 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 = []; + console.log(cusomeBy( x, 1, isPositive )); + t.deepEqual( cusomeBy( x, 1, 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 = [ 0, 0, 0, 1, 1 ]; + + out = cusomeBy( x, 1, predicate, ctx ); + expected = [ false, false, false, true, true ]; + + t.deepEqual( out, 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 ); + } +}); From 901935874e918dfe75a27eafa2daddd40e9ab0e6 Mon Sep 17 00:00:00 2001 From: adityacodes30 Date: Fri, 27 Sep 2024 01:31:14 +0530 Subject: [PATCH 4/5] feat: add cusome-by --- lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js index ac055542d32b..44612a73a02e 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js @@ -125,7 +125,6 @@ tape( 'the function cumulatively tests whether at least n elements in a provided tape( 'the function returns an empty array if provided an empty input array as first argument', function test( t ) { var x = []; - console.log(cusomeBy( x, 1, isPositive )); t.deepEqual( cusomeBy( x, 1, isPositive ), [], 'returns expected value' ); t.end(); }); From fe7e90a37a917d04f98704202794a5ba7be74720 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Sat, 28 Sep 2024 20:50:03 -0400 Subject: [PATCH 5/5] chore: minor clean-up --- .../@stdlib/array/base/cusome-by/README.md | 10 +++++----- .../base/cusome-by/benchmark/benchmark.js | 2 +- .../array/base/cusome-by/docs/repl.txt | 4 ++-- .../base/cusome-by/docs/types/index.d.ts | 19 +++++++++---------- .../array/base/cusome-by/examples/index.js | 2 +- .../array/base/cusome-by/lib/assign.js | 10 ++++++---- .../@stdlib/array/base/cusome-by/lib/index.js | 8 ++++++-- .../@stdlib/array/base/cusome-by/lib/main.js | 4 ++-- .../@stdlib/array/base/cusome-by/package.json | 2 +- .../array/base/cusome-by/test/test.assign.js | 11 +++++++---- .../array/base/cusome-by/test/test.main.js | 11 +++++++---- 11 files changed, 47 insertions(+), 36 deletions(-) diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/README.md b/lib/node_modules/@stdlib/array/base/cusome-by/README.md index 9ee64e64ee7a..60784e802c8d 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/README.md +++ b/lib/node_modules/@stdlib/array/base/cusome-by/README.md @@ -20,7 +20,7 @@ limitations under the License. # cusomeBy -> Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function. +> Cumulatively test whether at least `n` array elements in a provided array pass a test implemented by a predicate function.
@@ -32,7 +32,7 @@ var cusomeBy = require( '@stdlib/array/base/cusome-by' ); #### cusomeBy( x, n, predicate\[, thisArg ] ) -Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function. +Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function. ```javascript function fcn( value) { @@ -74,7 +74,7 @@ var count = context.count; #### cusomeBy.assign( x, n, out, stride, offset, predicate\[, thisArg ] ) -Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function and assigns the results to a provided output array. +Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function and assigns the results to a provided output array. ```javascript function fcn( v ) { @@ -119,8 +119,8 @@ function fcn( value ) { var x = bernoulli( 10, 0.8 ); console.log( x ); -// Cumulatively tests whether at least n array elements pass a test: -var y = cusomeBy( x, 2, fcn ); +// Cumulatively test whether at least three array elements are positive: +var y = cusomeBy( x, 3, fcn ); console.log( y ); ``` diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.js index 954f51ef2349..745230c884f3 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by/benchmark/benchmark.js @@ -39,7 +39,7 @@ bench( pkg+'::copy:len=100', function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - v = cusomeBy( x, 2, isPositiveInteger ); + v = cusomeBy( x, 50, isPositiveInteger ); if ( typeof v !== 'object' ) { b.fail( 'should return an array' ); } diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/docs/repl.txt b/lib/node_modules/@stdlib/array/base/cusome-by/docs/repl.txt index fc9d3037c901..6d723e8c6b60 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/base/cusome-by/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( x, n, predicate[, thisArg] ) - Cumulatively tests whether at least n array elements in a provided - array passes a test implemented by a predicate function. + Cumulatively tests whether at least n array elements in a provided array + pass a test implemented by a predicate function. The predicate function is provided three arguments: diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/index.d.ts index 6e540ceab1b4..2a54cb49177b 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/base/cusome-by/docs/types/index.d.ts @@ -71,7 +71,7 @@ type Predicate = Nullary | Unary | Binary | Ternary; */ interface CuSomeBy { /** - * Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. + * Cumulatively tests whether at least `n` array elements in a provided array passes a test implemented by a predicate function. * * @param x - input array * @param n - number of elements @@ -86,12 +86,12 @@ interface CuSomeBy { * var x = [ 0, 0, 0, 1, 1 ]; * * var y = cusomeBy( x, 2, isPositive ); - * // returns [ false, false, false, false, true, ]; + * // returns [ false, false, false, false, true ]; */ ( x: Collection | AccessorArrayLike, n: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; /** - * Cumulatively tests whether aleast n array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. + * Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. * * @param x - input array * @param n - number of elements @@ -115,7 +115,7 @@ interface CuSomeBy { assign( x: Collection | AccessorArrayLike, n: number, out: Array, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Array; /** - * Cumulatively tests whether atlest n array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. + * Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. * * @param x - input array * @param n - number of elements @@ -144,7 +144,7 @@ interface CuSomeBy { assign( x: Collection | AccessorArrayLike, n: number, out: U, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): U; /** - * Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. + * Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function and assigns the results to the provided output array. * * @param x - input array * @param n - number of elements @@ -162,15 +162,14 @@ interface CuSomeBy { * var x = [ 0, 0, 0, 1, 1 ]; * var y = [ false, null, false, null, false, null, false, null, false, null ]; * - * var arr = cusomeBy.assign( x, 2, y, 2, 0, isPositive );, + * var arr = cusomeBy.assign( x, 2, y, 2, 0, isPositive ); * // returns [ false, null, false, null, false, null, false, null, true, null ]; */ assign( x: Collection | AccessorArrayLike, n: number, out: Collection | AccessorArrayLike, stride: number, offset: number, predicate: Predicate, thisArg?: ThisParameterType> ): Collection | AccessorArrayLike; - } /** -* Cumulatively tests whether atleast n array elements in a provided array pass a test implemented by a predicate function. +* Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function. * * @param x - input array * @param n - number of elements @@ -180,7 +179,7 @@ interface CuSomeBy { * * @example * function isPositive( v ) { -* return ( v > 0 ); +* return ( v > 0 ); * } * var x = [ 0, 0, 0, 1, 1 ]; * @@ -189,7 +188,7 @@ interface CuSomeBy { * * @example * function isPositive( v ) { -* return ( v > 0 ); +* return ( v > 0 ); * } * var x = [ 0, 0, 0, 1, 1 ]; * var y = [ false, null, false, null, false, null, false, null, false, null ]; diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/examples/index.js b/lib/node_modules/@stdlib/array/base/cusome-by/examples/index.js index 8d44c323ade9..08f06cd8a6c7 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/examples/index.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by/examples/index.js @@ -29,6 +29,6 @@ function fcn( value ) { var x = bernoulli( 10, 0.8 ); console.log( x ); -// Cumulatively tests whether at least 3 array elements in a provided array passes a test implemented by a predicate function. +// Cumulatively test whether at least three array elements are positive: var y = cusomeBy( x, 3, fcn ); console.log( y ); diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/lib/assign.js b/lib/node_modules/@stdlib/array/base/cusome-by/lib/assign.js index 647965093a18..ca86d3800224 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/lib/assign.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by/lib/assign.js @@ -26,7 +26,7 @@ var arraylike2object = require( '@stdlib/array/base/arraylike2object' ); // FUNCTIONS // /** -* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function and assigns the results to elements in the provided output array. * * @private * @param {Collection} x - input array @@ -70,7 +70,8 @@ function indexed( x, n, out, stride, offset, predicate, thisArg ) { } /** -* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function and assigns the results to elements in the provided output array. +* * @private * @param {Object} x - input array object * @param {integer} n - number of elements @@ -92,7 +93,7 @@ function indexed( x, n, out, stride, offset, predicate, thisArg ) { * var x = toAccessorArray( [ false, false, false, true, true ] ); * * var out = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] ); -* var arr = accessors( arraylike2object( x ), 2, arraylike2object( out ), 2, 0, isPositive ); +* var arr = accessors( arraylike2object( x ), 2, arraylike2object( out ), 2, 0, isPositive ); * * var v = arr.get( 8 ); * // returns true @@ -132,7 +133,8 @@ function accessors( x, n, out, stride, offset, predicate, thisArg ) { // MAIN // /** -* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function and assigns the results to elements in the provided output array. +* * @param {Collection} x - input array * @param {integer} n - number of elements * @param {Collection} out - output array diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/lib/index.js b/lib/node_modules/@stdlib/array/base/cusome-by/lib/index.js index 9cbcf399e68c..6c5c66261cb9 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/lib/index.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* Cumulatively test whether at least `n` array elements in a provided array pass a test implemented by a predicate function. * * @module @stdlib/array/base/cusome-by * @@ -27,7 +27,7 @@ * var cusomeBy = require( '@stdlib/array/base/cusome-by' ); * * function isPositive( value ) { -* return ( value > 0 ); +* return ( value > 0 ); * } * * var x = [ 0, 0, 0, 1, 1 ]; @@ -37,6 +37,10 @@ * @example * var cusomeBy = require( '@stdlib/array/base/cusome-by' ); * +* function isPositive( value ) { +* return ( value > 0 ); +* } +* * var x = [ 0, 0, 0, 1, 1 ]; * * var y = [ false, null, false, null, false, null, false, null, false, null ]; diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/lib/main.js b/lib/node_modules/@stdlib/array/base/cusome-by/lib/main.js index f39660eff382..af404b913f04 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/lib/main.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by/lib/main.js @@ -27,7 +27,7 @@ var assign = require( './assign.js' ); // MAIN // /** -* Cumulatively tests whether at least n array elements in a provided array passes a test implemented by a predicate function. +* Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function. * * @param {Collection} x - input collection * @param {integer} n - number of elements @@ -37,7 +37,7 @@ var assign = require( './assign.js' ); * * @example * function isPositive( value ) { -* return ( value > 0 ); +* return ( value > 0 ); * } * * var x = [ 0, 0, 0, 1, 1 ]; diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/package.json b/lib/node_modules/@stdlib/array/base/cusome-by/package.json index 3694411308f1..aec14ef20860 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/package.json +++ b/lib/node_modules/@stdlib/array/base/cusome-by/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/array/base/cusome-by", "version": "0.0.0", - "description": "Cumulatively test whether at least n array elements in a provided array pass a test implemented by a predicate function.", + "description": "Cumulatively test whether at least `n` array elements in a provided array pass a test implemented by a predicate function.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.assign.js b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.assign.js index c9671ac0d07e..90b11ebad3a9 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.assign.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.assign.js @@ -26,19 +26,22 @@ var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' ); var cusomeBy = require( './../lib/assign.js' ); -// TESTS // +// FUNCTIONS // function isPositive( v ) { return ( v > 0 ); } + +// TESTS // + tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); t.strictEqual( typeof cusomeBy, 'function', 'main export is a function' ); t.end(); }); -tape( 'the function cumulatively tests whether at least n array elements in a provided array pass a test implemented by a predicate function (generic)', function test( t ) { +tape( 'the function cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function (generic)', function test( t ) { var expected; var actual; var x; @@ -92,7 +95,7 @@ tape( 'the function cumulatively tests whether at least n array elements in a pr t.end(); }); -tape( 'the function cumulatively tests whether at least n array elements in a provided array pass a test implemented by a predicate function (typed)', function test( t ) { +tape( 'the function cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function (typed)', function test( t ) { var expected; var actual; var x; @@ -146,7 +149,7 @@ tape( 'the function cumulatively tests whether at least n array elements in a pr t.end(); }); -tape( 'the function cumulatively tests whether at least n array elements in a provided array pass a test implemented by a predicate function (accessor)', function test( t ) { +tape( 'the function cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function (accessor)', function test( t ) { var expected; var actual; var ybuf; diff --git a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js index 44612a73a02e..c418d279da0a 100644 --- a/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js +++ b/lib/node_modules/@stdlib/array/base/cusome-by/test/test.main.js @@ -26,19 +26,22 @@ var Float64Array = require( '@stdlib/array/float64' ); var cusomeBy = require( './../lib' ); -// TESTS // +// FUNCTIONS // function isPositive( v ) { return ( v > 0 ); } + +// TESTS // + tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); t.strictEqual(typeof cusomeBy, 'function', 'main export is a function'); t.end(); }); -tape( 'the function cumulatively tests whether at least n elements in a provided array pass a test implemented by a predicate function (generic)', function test( t ) { +tape( 'the function cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function (generic)', function test( t ) { var expected; var actual; var x; @@ -67,7 +70,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided t.end(); }); -tape( 'the function cumulatively tests whether at least n elements in a provided array pass a test implemented by a predicate function (typed)', function test( t ) { +tape( 'the function cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function (typed)', function test( t ) { var expected; var actual; var x; @@ -90,7 +93,7 @@ tape( 'the function cumulatively tests whether at least n elements in a provided t.end(); }); -tape( 'the function cumulatively tests whether at least n elements in a provided array pass a test implemented by a predicate function (accessor array)', function test( t ) { +tape( 'the function cumulatively tests whether at least `n` elements in a provided array pass a test implemented by a predicate function (accessor array)', function test( t ) { var expected; var actual; var x;