Skip to content

Commit

Permalink
Merge branch 'stdlib-js:develop' into dcusumpw-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
headlessNode authored Oct 3, 2024
2 parents b951d99 + ca2fbd0 commit 8b4a302
Show file tree
Hide file tree
Showing 73 changed files with 7,040 additions and 347 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

{{alias}}( x, predicate[, thisArg] )
Cumulatively tests whether at least one array element in a provided array
passes a test implemented by a predicate function, while iterating from
Expand Down Expand Up @@ -27,9 +28,9 @@

Examples
--------
> function isPositive( v ) { return ( v > 0 ); };
> function predicate( v ) { return ( v > 0 ); };
> var x = [ 1, 1, 0, 0, 0 ];
> var y = {{alias}}( x, isPositive )
> var y = {{alias}}( x, predicate )
[ false, false, false, true, true ]


Expand Down Expand Up @@ -71,10 +72,10 @@

Examples
--------
> function isPositive( v ) { return ( v > 0 ); };
> var x = [ 1, 1, 0, 0 ];
> var out = [ false, null, false, null, false, null, false, null ];
> var arr = {{alias}}.assign( x, out, 2, 0, isPositive )
> function predicate( v ) { return ( v > 0 ); };
> var arr = {{alias}}.assign( x, out, 2, 0, predicate )
[ false, null, ..., true, null ]
> var bool = ( arr === out )
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ interface CuanyByRight {
*
* @example
* function isPositive( v ) {
* return v > 0;
* return v > 0;
* }
* var x = [ 1, 1, 0, 0, 0 ];
* var y = [ false, null, false, null, false, null, false, null, false, null ];
Expand Down Expand Up @@ -172,7 +172,7 @@ interface CuanyByRight {
*
* @example
* function isPositive( v ) {
* return v > 0;
* return v > 0;
* }
* var x = [ 1, 1, 0, 0, 0 ];
*
Expand All @@ -181,7 +181,7 @@ interface CuanyByRight {
*
* @example
* function isPositive( v ) {
* return v > 0;
* return v > 0;
* }
* var x = [ 0, 1, 1, 0, 0 ];
* var y = [ false, null, false, null, false, null, false, null, false, null ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* limitations under the License.
*/


import cuanyByRight = require( './index' );

/**
Expand Down Expand Up @@ -57,7 +56,24 @@ function isPositive( value: number ): boolean {
cuanyByRight( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[]
}

// The compiler throws an error if the function is provided a first argument which is not like a function..
// The compiler throws an error if the function is provided a first argument which is not an array-like object...
{
cuanyByRight( 1, isPositive ); // $ExpectError
cuanyByRight( true, isPositive ); // $ExpectError
cuanyByRight( false, isPositive ); // $ExpectError
cuanyByRight( null, isPositive ); // $ExpectError
cuanyByRight( void 0, isPositive ); // $ExpectError
cuanyByRight( {}, isPositive ); // $ExpectError

cuanyByRight( 1, isPositive, {} ); // $ExpectError
cuanyByRight( true, isPositive, {} ); // $ExpectError
cuanyByRight( false, isPositive, {} ); // $ExpectError
cuanyByRight( null, isPositive, {} ); // $ExpectError
cuanyByRight( void 0, isPositive, {} ); // $ExpectError
cuanyByRight( {}, isPositive, {} ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument which is not function...
{
const x = [ 1, 2, 3, 4 ];

Expand Down Expand Up @@ -87,7 +103,7 @@ function isPositive( value: number ): boolean {
const y = [ false, null, false, null, false, null, false, null, false, null ];

cuanyByRight.assign( x, y, 2, 0, isPositive ); // $ExpectType (boolean | null)[]
cuanyByRight.assign( x, y, 2, 0, isPositive, {} ); // $ExpectType (boolean | null)[]
cuanyByRight.assign( x, y, 2, 0, isPositive, {} ); // $ExpectType (boolean | null)[]
cuanyByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array
cuanyByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array
cuanyByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array
Expand Down Expand Up @@ -148,7 +164,6 @@ function isPositive( value: number ): boolean {
cuanyByRight.assign( x, {}, 2, 0, isPositive, {} ); // $ExpectError
}


// The compiler throws an error if the `assign` method is provided a third argument which is not a number...
{
const x = [ false, false, true, false, false ];
Expand Down Expand Up @@ -193,7 +208,7 @@ function isPositive( value: number ): boolean {
cuanyByRight.assign( x, y, 1, [], isPositive, {} ); // $ExpectError
}

// The compiler throws an error if the `assign` method is provided a fourth argument which is not like a function...
// The compiler throws an error if the `assign` method is provided a fifth argument which is not like a function...
{
const x = [ false, false, true, false, false ];
const y = [ false, null, false, null, false, null, false, null, false, null ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@
*
* var x = [ 0, 1, 0, 0, 0 ];
*
* var y1 = cuanyByRight( x, isPositive );
* // returns [ false, false, false, true, true ]
*
* var y2 = [ false, null, false, null, false, null, false, null, false, null ];
* var out = cuanyByRight.assign( x, y2, 2, 0, isPositive );
* var y = [ false, null, false, null, false, null, false, null, false, null ];
* var out = cuanyByRight.assign( x, y, 2, 0, isPositive );
* // returns [ false, null, false, null, false, null, true, null, true, null ]
*
* var bool = ( out === y2 );
* var bool = ( out === y );
* // returns true
*/

Expand Down
1 change: 1 addition & 0 deletions lib/node_modules/@stdlib/array/base/cuany-by/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ function isPositive( value ) {
var x = bernoulli( 10, 0.1 );
console.log( x );

// Cumulatively determine whether at least one element is positive:
var out = cuanyBy( x, isPositive );
console.log( out );
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var isArray = require( '@stdlib/assert/is-array' );
var filled = require( '@stdlib/array/base/filled' );
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
var pkg = require( '@stdlib/array/base/cuany-by/package.json' ).name;
var cuanyBy = require( '@stdlib/array/base/cuany-by/lib' );
var cuanyBy = require( './../lib' );


// FUNCTIONS //
Expand All @@ -39,7 +39,7 @@ var cuanyBy = require( '@stdlib/array/base/cuany-by/lib' );
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var x = filled( 1.5, len );
var x = filled( 0, len );
return benchmark;

/**
Expand Down
3 changes: 3 additions & 0 deletions lib/node_modules/@stdlib/array/base/cuany-by/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@
predicate: Function
Predicate function.

thisArg: any (optional)
Execution context.

Returns
-------
y: ArrayLikeObject
Expand Down
22 changes: 19 additions & 3 deletions lib/node_modules/@stdlib/array/base/cuany-by/docs/types/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,24 @@ function isPositive( value: number ): boolean {
cuanyBy( new Uint8ClampedArray( [ 1, 2, 3 ] ), isPositive, {} ); // $ExpectType boolean[]
}

// The compiler throws an error if the function is provided a first argument which is not like a function..
// The compiler throws an error if the function is provided a first argument which is not an array-like object...
{
cuanyBy( 1, isPositive ); // $ExpectError
cuanyBy( true, isPositive ); // $ExpectError
cuanyBy( false, isPositive ); // $ExpectError
cuanyBy( null, isPositive ); // $ExpectError
cuanyBy( void 0, isPositive ); // $ExpectError
cuanyBy( {}, isPositive ); // $ExpectError

cuanyBy( 1, isPositive, {} ); // $ExpectError
cuanyBy( true, isPositive, {} ); // $ExpectError
cuanyBy( false, isPositive, {} ); // $ExpectError
cuanyBy( null, isPositive, {} ); // $ExpectError
cuanyBy( void 0, isPositive, {} ); // $ExpectError
cuanyBy( {}, isPositive, {} ); // $ExpectError
}

// The compiler throws an error if the function is provided a second argument which is not function...
{
const x = [ 1, 2, 3, 4 ];

Expand Down Expand Up @@ -147,7 +164,6 @@ function isPositive( value: number ): boolean {
cuanyBy.assign( x, {}, 2, 0, isPositive, {} ); // $ExpectError
}


// The compiler throws an error if the `assign` method is provided a third argument which is not a number...
{
const x = [ false, false, true, false, false ];
Expand Down Expand Up @@ -192,7 +208,7 @@ function isPositive( value: number ): boolean {
cuanyBy.assign( x, y, 1, [], isPositive, {} ); // $ExpectError
}

// The compiler throws an error if the `assign` method is provided a fourth argument which is not like a function...
// The compiler throws an error if the `assign` method is provided a fifth argument which is not like a function...
{
const x = [ false, false, true, false, false ];
const y = [ false, null, false, null, false, null, false, null, false, null ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
'use strict';

var bernoulli = require( '@stdlib/random/array/bernoulli' );
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' );
var cuanyBy = require( './../lib' );

function isPositive( value ) {
return ( value > 0 );
}

// Create an array of random values:
var x = bernoulli( 10, 0.1 );
console.log( x );

// Cumulatively determine whether values are truthy:
var out = cuanyBy( x, isPositiveInteger );
// Cumulatively determine whether at least one element is positive:
var out = cuanyBy( x, isPositive );
console.log( out );
8 changes: 4 additions & 4 deletions lib/node_modules/@stdlib/array/base/cuany-by/lib/assign.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,13 @@ function indexed( x, y, stride, offset, predicate, thisArg ) {
* @returns {Collection} output array
*
* @example
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* function isPositive( v ) {
* return v > 0;
* }
*
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
*
* var x = toAccessorArray( [ false, false, false, true, false ] );
* var y = toAccessorArray( [ false, null, false, null, false, null, false, null, false, null ] );
*
Expand Down Expand Up @@ -136,7 +136,7 @@ function accessors( x, y, stride, offset, predicate, thisArg ) {
// MAIN //

/**
* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function and assigns results to provided output array.
* Cumulatively tests whether at least one element in a provided array passes a test implemented by a predicate function and assigns results to a provided output array.
*
* @param {Collection} x - input array
* @param {Collection} y - output array
Expand Down
Loading

0 comments on commit 8b4a302

Please sign in to comment.