Skip to content

Commit c9949c5

Browse files
committedSep 29, 2024·
Auto-generated commit
1 parent a7f1507 commit c9949c5

16 files changed

+1722
-2
lines changed
 

‎CHANGELOG.md

+37-2
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,40 @@ This release closes the following issue:
225225

226226
<!-- /.package -->
227227

228+
<section class="package" id="array-base-cuevery-by-right-unreleased">
229+
230+
#### [@stdlib/array/base/cuevery-by-right](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/cuevery-by-right)
231+
232+
<details>
233+
234+
<section class="features">
235+
236+
##### Features
237+
238+
- [`5a50038`](https://github.com/stdlib-js/stdlib/commit/5a50038db6a457856adc51d5e6e3fd7161f45085) - add `array/base/cuevery-by-right` [(#2802)](https://github.com/stdlib-js/stdlib/pull/2802)
239+
240+
</section>
241+
242+
<!-- /.features -->
243+
244+
<section class="issues">
245+
246+
##### Closed Issues
247+
248+
This release closes the following issue:
249+
250+
[#2328](https://github.com/stdlib-js/stdlib/issues/2328)
251+
252+
</section>
253+
254+
<!-- /.issues -->
255+
256+
</details>
257+
258+
</section>
259+
260+
<!-- /.package -->
261+
228262
<section class="package" id="array-base-cunone-by-unreleased">
229263

230264
#### [@stdlib/array/base/cunone-by](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/cunone-by)
@@ -651,9 +685,9 @@ This release closes the following issue:
651685

652686
### Closed Issues
653687

654-
A total of 2 issues were closed in this release:
688+
A total of 3 issues were closed in this release:
655689

656-
[#2326](https://github.com/stdlib-js/stdlib/issues/2326), [#2327](https://github.com/stdlib-js/stdlib/issues/2327)
690+
[#2326](https://github.com/stdlib-js/stdlib/issues/2326), [#2327](https://github.com/stdlib-js/stdlib/issues/2327), [#2328](https://github.com/stdlib-js/stdlib/issues/2328)
657691

658692
</section>
659693

@@ -684,6 +718,7 @@ A total of 8 people contributed to this release. Thank you to the following cont
684718

685719
<details>
686720

721+
- [`5a50038`](https://github.com/stdlib-js/stdlib/commit/5a50038db6a457856adc51d5e6e3fd7161f45085) - **feat:** add `array/base/cuevery-by-right` [(#2802)](https://github.com/stdlib-js/stdlib/pull/2802) _(by HarshaNP, Philipp Burckhardt)_
687722
- [`006e24c`](https://github.com/stdlib-js/stdlib/commit/006e24cbe344a32a48d883dfa9991e7a381a0b98) - **chore:** update package meta data [(#2964)](https://github.com/stdlib-js/stdlib/pull/2964 ) _(by stdlib-bot)_
688723
- [`9835dae`](https://github.com/stdlib-js/stdlib/commit/9835dae5a4dba0aae50d8582b97ad69d17fefe6d) - **feat:** add `array/base/cusome-by` [(#2953)](https://github.com/stdlib-js/stdlib/pull/2953) _(by Aditya Sapra, Philipp Burckhardt)_
689724
- [`abf0407`](https://github.com/stdlib-js/stdlib/commit/abf040787f6598438b0100a729a8331b7f80f62f) - **chore:** resolve lint errors in TS files _(by Philipp Burckhardt)_

‎base/cuevery-by-right/README.md

+145
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
<!--
2+
3+
@license Apache-2.0
4+
5+
Copyright (c) 2024 The Stdlib Authors.
6+
7+
Licensed under the Apache License, Version 2.0 (the "License");
8+
you may not use this file except in compliance with the License.
9+
You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
21+
# cueveryByRight
22+
23+
> Cumulatively test whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var cueveryByRight = require( '@stdlib/array/base/cuevery-by-right' );
31+
```
32+
33+
#### cueveryByRight( x, predicate\[, thisArg ] )
34+
35+
Cumulatively tests whether every array element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left.
36+
37+
```javascript
38+
function fcn( value ) {
39+
return value > 0;
40+
}
41+
42+
var x = [ 0, 0, 1, 1, 1 ];
43+
44+
var y = cueveryByRight( x, fcn );
45+
// returns [ true, true, true, false, false ];
46+
```
47+
48+
#### cueveryByRight.assign( x, out, stride, offset, predicate\[, thisArg ] )
49+
50+
Cumulatively tests whether every array element in a provided array passes a test implemented by a `predicate` function, while iterating from right-to-left, and assigns the results to the elements in the output array.
51+
52+
```javascript
53+
function fcn( v ) {
54+
return v > 0;
55+
}
56+
57+
var x = [ 0, 0, 1, 1, 1 ];
58+
var y = [ false, null, false, null, false, null, false, null, false, null ];
59+
60+
var out = cueveryByRight.assign( x, y, 2, 0, fcn );
61+
// returns [ true, null, true, null, true, null, false, null, false, null ]
62+
63+
var bool = ( out === y );
64+
// returns true
65+
```
66+
67+
The invoked `predicate` function is provided three arguments:
68+
69+
- **value**: collection element,
70+
- **index**: collection index,
71+
- **collection**: input collection,
72+
73+
To set the function execution context, provide a `thisArg`.
74+
75+
```javascript
76+
function fcn( v ) {
77+
this.count += 1;
78+
return ( v > 0 );
79+
}
80+
81+
var x = [ 0, 0, 1, 1, 1 ];
82+
83+
var context = {
84+
'count': 0
85+
};
86+
87+
var bool = cueveryByRight( x, fcn, context );
88+
// returns [ true, true, true, false, false ]
89+
90+
var count = context.count;
91+
// returns 4
92+
```
93+
94+
</section>
95+
96+
<!-- /.usage -->
97+
98+
<section class="notes">
99+
100+
</section>
101+
102+
<!-- /.notes -->
103+
104+
<section class="examples">
105+
106+
## Examples
107+
108+
<!-- eslint no-undef: "error" -->
109+
110+
```javascript
111+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
112+
var cueveryByRight = require( '@stdlib/array/base/cuevery-by-right' );
113+
114+
function isPositive( value ) {
115+
return ( value > 0 );
116+
}
117+
118+
// Create an array of random values:
119+
var x = discreteUniform( 10, -10, 10 );
120+
console.log( x );
121+
122+
// Cumulatively test whether every array element passes a test, while iterating from right-to-left:
123+
var out = cueveryByRight( x, isPositive );
124+
console.log( out );
125+
```
126+
127+
</section>
128+
129+
<!-- /.examples -->
130+
131+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
132+
133+
<section class="related">
134+
135+
</section>
136+
137+
<!-- /.related -->
138+
139+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
140+
141+
<section class="links">
142+
143+
</section>
144+
145+
<!-- /.links -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isArray = require( '@stdlib/assert/is-array' );
26+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
27+
var filled = require( './../../../base/filled' );
28+
var pkg = require( './../package.json' ).name;
29+
var cueveryByRight = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var x = filled( 1.5, len );
43+
return benchmark;
44+
45+
/**
46+
* Benchmark function.
47+
*
48+
* @private
49+
* @param {Benchmark} b - benchmark instance
50+
*/
51+
function benchmark( b ) {
52+
var y;
53+
var v;
54+
var i;
55+
56+
y = filled( false, len );
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
v = cueveryByRight.assign( x, y, 1, 0, isPositiveInteger );
61+
if ( typeof v !== 'object' ) {
62+
b.fail( 'should return an array' );
63+
}
64+
}
65+
b.toc();
66+
if ( !isArray( v ) ) {
67+
b.fail( 'should return an array' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
}
72+
}
73+
74+
75+
// MAIN //
76+
77+
/**
78+
* Main execution sequence.
79+
*
80+
* @private
81+
*/
82+
function main() {
83+
var len;
84+
var min;
85+
var max;
86+
var f;
87+
var i;
88+
89+
min = 1; // 10^min
90+
max = 6; // 10^max
91+
92+
for ( i = min; i <= max; i++ ) {
93+
len = pow( 10, i );
94+
f = createBenchmark( len );
95+
bench( pkg+':assign:len='+len, f );
96+
}
97+
}
98+
99+
main();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var isArray = require( '@stdlib/assert/is-array' );
25+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var cueveryByRight = require( './../lib' );
28+
29+
30+
// MAIN //
31+
32+
bench( pkg, function benchmark( b ) {
33+
var x;
34+
var i;
35+
var v;
36+
37+
x = [ 0, 0, 1, 1, 1 ];
38+
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
v = cueveryByRight( x, isPositiveInteger );
42+
if ( typeof v !== 'object' ) {
43+
b.fail( 'should return an array' );
44+
}
45+
}
46+
b.toc();
47+
if ( !isArray( v ) ) {
48+
b.fail( 'should return an array' );
49+
}
50+
b.pass( 'benchmark finished' );
51+
b.end();
52+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var pow = require( '@stdlib/math/base/special/pow' );
25+
var isArray = require( '@stdlib/assert/is-array' );
26+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
27+
var filled = require( './../../../base/filled' );
28+
var pkg = require( './../package.json' ).name;
29+
var cueveryByRight = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var x = filled( 1.5, len );
43+
return benchmark;
44+
45+
/**
46+
* Benchmark function.
47+
*
48+
* @private
49+
* @param {Benchmark} b - benchmark instance
50+
*/
51+
function benchmark( b ) {
52+
var v;
53+
var i;
54+
55+
b.tic();
56+
for ( i = 0; i < b.iterations; i++ ) {
57+
v = cueveryByRight( x, isPositiveInteger );
58+
if ( typeof v !== 'object' ) {
59+
b.fail( 'should return an array' );
60+
}
61+
}
62+
b.toc();
63+
if ( !isArray( v ) ) {
64+
b.fail( 'should return an array' );
65+
}
66+
b.pass( 'benchmark finished' );
67+
b.end();
68+
}
69+
}
70+
71+
72+
// MAIN //
73+
74+
/**
75+
* Main execution sequence.
76+
*
77+
* @private
78+
*/
79+
function main() {
80+
var len;
81+
var min;
82+
var max;
83+
var f;
84+
var i;
85+
86+
min = 1; // 10^min
87+
max = 6; // 10^max
88+
89+
for ( i = min; i <= max; i++ ) {
90+
len = pow( 10, i );
91+
f = createBenchmark( len );
92+
bench( pkg + ':len=' + len, f );
93+
}
94+
}
95+
96+
main();

‎base/cuevery-by-right/docs/repl.txt

+83
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{{alias}}( x, predicate[, thisArg] )
2+
Cumulatively tests whether every array element in a provided array
3+
passes a test implemented by a predicate function, while iterating from
4+
right-to-left.
5+
6+
The predicate function is provided three arguments:
7+
8+
- value: current array element.
9+
- index: current array element index.
10+
- arr: the input array.
11+
12+
Parameters
13+
----------
14+
x: ArrayLikeObject
15+
Input array.
16+
17+
predicate: Function
18+
Predicate function.
19+
20+
thisArg: any (optional)
21+
Execution context.
22+
23+
Returns
24+
-------
25+
out: Array
26+
Output array.
27+
28+
Examples
29+
--------
30+
> function fcn( v ) { return ( v > 0 ); };
31+
> var x = [ 0, 0, 1, 1, 1 ];
32+
> var y = {{alias}}( x, fcn )
33+
[ true, true, true, false, false ]
34+
35+
36+
{{alias}}.assign( x, out, stride, offset, predicate[, thisArg] )
37+
Cumulatively tests whether every array element in a provided array passes a
38+
test implemented by a predicate function, while iterating from right-to-
39+
left, and assigns the results to the provided output array.
40+
41+
The predicate function is provided three arguments:
42+
43+
- value: current array element.
44+
- index: current array element index.
45+
- arr: the input array.
46+
47+
Parameters
48+
----------
49+
x: ArrayLikeObject
50+
Input array.
51+
52+
out: ArrayLikeObject
53+
Output array.
54+
55+
stride: integer
56+
Output array stride.
57+
58+
offset: integer
59+
Output array offset.
60+
61+
predicate: Function
62+
Predicate function.
63+
64+
thisArg: any (optional)
65+
Execution context.
66+
67+
Returns
68+
-------
69+
out: ArrayLikeObject
70+
Output array.
71+
72+
Examples
73+
--------
74+
> function fcn( v ) { return ( v > 0 ); };
75+
> var x = [ 0, 0, 1, 1 ];
76+
> var out = [ false, null, false, null, false, null, false, null ];
77+
> var arr = {{alias}}.assign( x, out, 2, 0, fcn )
78+
[ true, null, true, null, false, null, false, null ]
79+
> var bool = ( arr === out )
80+
true
81+
82+
See Also
83+
--------
+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
// TypeScript Version: 4.1
20+
21+
/// <reference types="@stdlib/types"/>
22+
23+
import { Collection, AccessorArrayLike, TypedArray, BooleanArray } from '@stdlib/types/array';
24+
25+
/**
26+
* Checks whether an element in a collection passes a test.
27+
*
28+
* @returns boolean indicating whether an element in a collection passes a test
29+
*/
30+
type Nullary<U> = ( this: U ) => boolean;
31+
32+
/**
33+
* Checks whether an element in a collection passes a test.
34+
*
35+
* @param value - collection value
36+
* @returns boolean indicating whether an element in a collection passes a test
37+
*/
38+
type Unary<T, U> = ( this: U, value: T ) => boolean;
39+
40+
/**
41+
* Checks whether an element in a collection passes a test.
42+
*
43+
* @param value - collection value
44+
* @param index - collection index
45+
* @returns boolean indicating whether an element in a collection passes a test
46+
*/
47+
type Binary<T, U> = ( this: U, value: T, index: number ) => boolean;
48+
49+
/**
50+
* Checks whether an element in a collection passes a test.
51+
*
52+
* @param value - collection value
53+
* @param index - collection index
54+
* @param collection - input collection
55+
* @returns boolean indicating whether an element in a collection passes a test
56+
*/
57+
type Ternary<T, U> = ( this: U, value: T, index: number, collection: Collection<T> ) => boolean;
58+
59+
/**
60+
* Checks whether an element in a collection passes a test.
61+
*
62+
* @param value - collection value
63+
* @param index - collection index
64+
* @param collection - input collection
65+
* @returns boolean indicating whether an element in a collection passes a test
66+
*/
67+
type Predicate<T, U> = Nullary<U> | Unary<T, U> | Binary<T, U> | Ternary<T, U>;
68+
69+
/**
70+
* Interface describing `cueveryByRight`.
71+
*/
72+
interface CueveryByRight {
73+
/**
74+
* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.
75+
*
76+
* @param x - input array
77+
* @param predicate - test function
78+
* @param thisArg - execution context
79+
* @returns output array
80+
*
81+
* @example
82+
* function isPositive( v ) {
83+
* return v > 0;
84+
* }
85+
* var x = [ 1, 0, 0, 1, 1 ];
86+
*
87+
* var y = cueveryByRight( x, isPositive );
88+
* // returns [ true, true, false, false, false ];
89+
*/
90+
<T = unknown, U = unknown>( x: Collection<T> | AccessorArrayLike<T>, predicate: Predicate<T, U>, thisArg?: ThisParameterType<Predicate<T, U>> ): Array<boolean>;
91+
92+
/**
93+
* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array.
94+
*
95+
* @param x - input array
96+
* @param y - output array
97+
* @param stride - output array stride
98+
* @param offset - output array offset
99+
* @param predicate - test function
100+
* @param thisArg - execution context
101+
* @returns output array
102+
*
103+
* @example
104+
* function isPositive( v ) {
105+
* return v > 0;
106+
* }
107+
* var x = [ 0, 0, 1, 1, 1 ];
108+
* var y = [ false, null, false, null, false, null, false, null, false, null ];
109+
*
110+
* var arr = cueveryByRight.assign( x, y, 2, 0, isPositive );
111+
* // returns [ true, null, true, null, true, null, false, null, false, null ];
112+
*/
113+
assign<T = unknown, U = unknown, V = unknown>( x: Collection<T> | AccessorArrayLike<T>, out: Array<U>, stride: number, offset: number, predicate: Predicate<T, V>, thisArg?: ThisParameterType<Predicate<T, V>> ): Array<U | boolean>;
114+
115+
/**
116+
* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array.
117+
*
118+
* @param x - input array
119+
* @param out - output array
120+
* @param stride - output array stride
121+
* @param offset - output array offset
122+
* @param predicate - test function
123+
* @param thisArg - execution context
124+
* @returns output array
125+
*
126+
* @example
127+
* var BooleanArray = require( './../../../../bool' );
128+
*
129+
* function isPositive( v ) {
130+
* return ( v > 0 );
131+
* }
132+
* var x = [ 0, 0, 0, 1, 0 ];
133+
* var y = new BooleanArray( [ false, false, false, false, false, false, false, false, false, false ] );
134+
*
135+
* var arr = cueveryByRight.assign( x, y, 2, 0, isPositive );
136+
* // returns <BooleanArray>
137+
*
138+
* var v = arr.get( 4 );
139+
* // returns false
140+
*/
141+
assign<T, U extends TypedArray | BooleanArray, V = unknown>( x: Collection<T> | AccessorArrayLike<T>, out: U, stride: number, offset: number, predicate: Predicate<T, V>, thisArg?: ThisParameterType<Predicate<T, V>> ): U;
142+
143+
/**
144+
* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to the provided output array.
145+
*
146+
* @param x - input array
147+
* @param y - output array
148+
* @param stride - output array stride
149+
* @param offset - output array offset
150+
* @param predicate - test function
151+
* @param thisArg - execution context
152+
* @returns output array
153+
*
154+
* @example
155+
* function isPositive( v ) {
156+
* return v > 0;
157+
* }
158+
* var x = [ 0, 0, 1, 1, 1 ];
159+
* var y = [ false, null, false, null, false, null, false, null, false, null ];
160+
*
161+
* var arr = cueveryByRight.assign( x, y, 2, 0, isPositive );
162+
* // returns [ true, null, true, null, true, null, false, null, false, null ];
163+
*/
164+
assign<T = unknown, U = unknown, V = unknown>( x: Collection<T> | AccessorArrayLike<T>, out: Collection<U> | AccessorArrayLike<U>, stride: number, offset: number, predicate: Predicate<T, V>, thisArg?: ThisParameterType<Predicate<T, V>> ): Collection<U | boolean> | AccessorArrayLike<U | boolean>;
165+
}
166+
167+
/**
168+
* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.
169+
*
170+
* @param x - input array
171+
* @param predicate - test function
172+
* @param thisArg - execution context
173+
* @returns output array
174+
*
175+
* @example
176+
* function isPositive( v ) {
177+
* return v > 0;
178+
* }
179+
* var x = [ 0, 0, 1, 1, 1 ];
180+
*
181+
* var result = cueveryByRight( x, isPositive );
182+
* // returns [ true, true, true, false, false ]
183+
*
184+
* @example
185+
* function isPositive( v ) {
186+
* return v > 0;
187+
* }
188+
* var x = [ 1, 0, 0, 1, 1 ];
189+
* var y = [ false, null, false, null, false, null, false, null, false, null ];
190+
*
191+
* var arr = cueveryByRight.assign( x, 2, y, 2, 0, isPositive );
192+
* // returns [ true, null, true, null, false, null, false, null, false, null ]
193+
*/
194+
declare var cueveryByRight: CueveryByRight;
195+
196+
197+
// EXPORTS //
198+
199+
export = cueveryByRight;
+209
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
/*
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
20+
import cueveryByRight = require( './index' );
21+
22+
const isPositive = ( v: number ): boolean => {
23+
return ( v > 0 );
24+
};
25+
26+
// TESTS //
27+
28+
// The function returns an array...
29+
{
30+
cueveryByRight( [ 0, 1, 1 ], isPositive ); // $ExpectType boolean[]
31+
cueveryByRight( [ -1, 0, 1, 2 ], isPositive ); // $ExpectType boolean[]
32+
}
33+
34+
// The compiler throws an error if the function is provided a first argument which is not an array-like object...
35+
{
36+
cueveryByRight( 1 ); // $ExpectError
37+
cueveryByRight( true ); // $ExpectError
38+
cueveryByRight( false ); // $ExpectError
39+
cueveryByRight( null ); // $ExpectError
40+
cueveryByRight( void 0 ); // $ExpectError
41+
cueveryByRight( {} ); // $ExpectError
42+
}
43+
44+
// The compiler throws an error if the function is provided a second argument which is not a function...
45+
{
46+
const x = [ 0, 0, 1, 1, 1 ];
47+
48+
cueveryByRight( x, '1' ); // $ExpectError
49+
cueveryByRight( x, true ); // $ExpectError
50+
cueveryByRight( x, false ); // $ExpectError
51+
cueveryByRight( x, 'abc' ); // $ExpectError
52+
cueveryByRight( x, void 0 ); // $ExpectError
53+
cueveryByRight( x, {} ); // $ExpectError
54+
cueveryByRight( x, [] ); // $ExpectError
55+
56+
cueveryByRight( x, '1', {} ); // $ExpectError
57+
cueveryByRight( x, true, {} ); // $ExpectError
58+
cueveryByRight( x, false, {} ); // $ExpectError
59+
cueveryByRight( x, 'abc', {} ); // $ExpectError
60+
cueveryByRight( x, void 0, {} ); // $ExpectError
61+
cueveryByRight( x, {}, {} ); // $ExpectError
62+
cueveryByRight( x, [], {} ); // $ExpectError
63+
}
64+
65+
// The compiler throws an error if the function is provided an unsupported number of arguments...
66+
{
67+
cueveryByRight(); // $ExpectError
68+
cueveryByRight( [] ); // $ExpectError
69+
cueveryByRight( [], [], [], [] ); // $ExpectError
70+
}
71+
72+
// Attached to the main export is an `assign` method which returns a collection...
73+
{
74+
const x = [ 1, 2, 3, 4 ];
75+
cueveryByRight.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive ); // $ExpectType (number | boolean)[]
76+
cueveryByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive ); // $ExpectType Float64Array
77+
cueveryByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive ); // $ExpectType Float32Array
78+
cueveryByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive ); // $ExpectType Int32Array
79+
cueveryByRight.assign( x, new Int16Array( 4 ), 1, 0, isPositive ); // $ExpectType Int16Array
80+
cueveryByRight.assign( x, new Int8Array( 4 ), 1, 0, isPositive ); // $ExpectType Int8Array
81+
cueveryByRight.assign( x, new Uint32Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint32Array
82+
cueveryByRight.assign( x, new Uint16Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint16Array
83+
cueveryByRight.assign( x, new Uint8Array( 4 ), 1, 0, isPositive ); // $ExpectType Uint8Array
84+
cueveryByRight.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive ); // $ExpectType Uint8ClampedArray
85+
86+
cueveryByRight.assign( x, [ 0, 0, 0, 0 ], 1, 0, isPositive, {} ); // $ExpectType (number | boolean)[]
87+
cueveryByRight.assign( x, new Float64Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float64Array
88+
cueveryByRight.assign( x, new Float32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Float32Array
89+
cueveryByRight.assign( x, new Int32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int32Array
90+
cueveryByRight.assign( x, new Int16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int16Array
91+
cueveryByRight.assign( x, new Int8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Int8Array
92+
cueveryByRight.assign( x, new Uint32Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint32Array
93+
cueveryByRight.assign( x, new Uint16Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint16Array
94+
cueveryByRight.assign( x, new Uint8Array( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8Array
95+
cueveryByRight.assign( x, new Uint8ClampedArray( 4 ), 1, 0, isPositive, {} ); // $ExpectType Uint8ClampedArray
96+
}
97+
98+
// The compiler throws an error if the `assign` method is provided a first argument which is not an array-like object...
99+
{
100+
const x = [ 0, 0, 1, 1, 1 ];
101+
102+
cueveryByRight.assign( 1, x, 2, 0, isPositive ); // $ExpectError
103+
cueveryByRight.assign( true, x, 2, 0, isPositive ); // $ExpectError
104+
cueveryByRight.assign( false, x, 2, 0, isPositive ); // $ExpectError
105+
cueveryByRight.assign( null, x, 2, 0, isPositive ); // $ExpectError
106+
cueveryByRight.assign( void 0, x, 2, 0, isPositive ); // $ExpectError
107+
cueveryByRight.assign( {}, x, 2, 0, isPositive ); // $ExpectError
108+
109+
cueveryByRight.assign( 1, x, 2, 0, isPositive, {} ); // $ExpectError
110+
cueveryByRight.assign( true, x, 2, 0, isPositive, {} ); // $ExpectError
111+
cueveryByRight.assign( false, x, 2, 0, isPositive, {} ); // $ExpectError
112+
cueveryByRight.assign( null, x, 2, 0, isPositive, {} ); // $ExpectError
113+
cueveryByRight.assign( void 0, x, 2, 0, isPositive, {} ); // $ExpectError
114+
cueveryByRight.assign( {}, x, 2, 0, isPositive, {} ); // $ExpectError
115+
}
116+
117+
// The compiler throws an error if the `assign` method is provided a second argument which is not an array-like object...
118+
{
119+
const x = [ 0, 0, 1, 1, 1 ];
120+
121+
cueveryByRight.assign( x, true, 1, 0, isPositive ); // $ExpectError
122+
cueveryByRight.assign( x, false, 1, 0, isPositive ); // $ExpectError
123+
cueveryByRight.assign( x, null, 1, 0, isPositive ); // $ExpectError
124+
cueveryByRight.assign( x, void 0, 1, 0, isPositive ); // $ExpectError
125+
cueveryByRight.assign( x, {}, 1, 0, isPositive ); // $ExpectError
126+
cueveryByRight.assign( x, 1, 1, 0, isPositive ); // $ExpectError
127+
128+
cueveryByRight.assign( x, true, 1, 0, isPositive, {} ); // $ExpectError
129+
cueveryByRight.assign( x, false, 1, 0, isPositive, {} ); // $ExpectError
130+
cueveryByRight.assign( x, null, 1, 0, isPositive, {} ); // $ExpectError
131+
cueveryByRight.assign( x, void 0, 1, 0, isPositive, {} ); // $ExpectError
132+
cueveryByRight.assign( x, {}, 1, 0, isPositive, {} ); // $ExpectError
133+
cueveryByRight.assign( x, 1, 1, 0, isPositive, {} ); // $ExpectError
134+
}
135+
136+
// The compiler throws an error if the `assign` method is provided a third argument which is not a number...
137+
{
138+
const x = [ 0, 0, 1, 1, 1 ];
139+
const y = [ false, null, false, null, false, null, false, null, false, null ];
140+
141+
cueveryByRight.assign( x, y, '1', 0, isPositive ); // $ExpectError
142+
cueveryByRight.assign( x, y, true, 0, isPositive ); // $ExpectError
143+
cueveryByRight.assign( x, y, false, 0, isPositive ); // $ExpectError
144+
cueveryByRight.assign( x, y, null, 0, isPositive ); // $ExpectError
145+
cueveryByRight.assign( x, y, void 0, 0, isPositive ); // $ExpectError
146+
cueveryByRight.assign( x, y, {}, 0, isPositive ); // $ExpectError
147+
cueveryByRight.assign( x, y, [], 0, isPositive ); // $ExpectError
148+
149+
cueveryByRight.assign( x, y, '1', 0, isPositive, {} ); // $ExpectError
150+
cueveryByRight.assign( x, y, true, 0, isPositive, {} ); // $ExpectError
151+
cueveryByRight.assign( x, y, false, 0, isPositive, {} ); // $ExpectError
152+
cueveryByRight.assign( x, y, null, 0, isPositive, {} ); // $ExpectError
153+
cueveryByRight.assign( x, y, void 0, 0, isPositive, {} ); // $ExpectError
154+
cueveryByRight.assign( x, y, {}, 0, isPositive, {} ); // $ExpectError
155+
cueveryByRight.assign( x, y, [], 0, isPositive, {} ); // $ExpectError
156+
}
157+
158+
// The compiler throws an error if the `assign` method is provided a fourth argument which is not a number...
159+
{
160+
const x = [ 0, 0, 1, 1, 1 ];
161+
const y = [ false, null, false, null, false, null, false, null, false, null ];
162+
163+
cueveryByRight.assign( x, y, 1, '1', isPositive ); // $ExpectError
164+
cueveryByRight.assign( x, y, 1, true, isPositive ); // $ExpectError
165+
cueveryByRight.assign( x, y, 1, false, isPositive ); // $ExpectError
166+
cueveryByRight.assign( x, y, 1, null, isPositive ); // $ExpectError
167+
cueveryByRight.assign( x, y, 1, void 0, isPositive ); // $ExpectError
168+
cueveryByRight.assign( x, y, 1, {}, isPositive ); // $ExpectError
169+
cueveryByRight.assign( x, y, 1, [], isPositive ); // $ExpectError
170+
171+
cueveryByRight.assign( x, y, 1, '1', isPositive, {} ); // $ExpectError
172+
cueveryByRight.assign( x, y, 1, true, isPositive, {} ); // $ExpectError
173+
cueveryByRight.assign( x, y, 1, false, isPositive, {} ); // $ExpectError
174+
cueveryByRight.assign( x, y, 1, null, isPositive, {} ); // $ExpectError
175+
cueveryByRight.assign( x, y, 1, void 0, isPositive, {} ); // $ExpectError
176+
cueveryByRight.assign( x, y, 1, {}, isPositive, {} ); // $ExpectError
177+
cueveryByRight.assign( x, y, 1, [], isPositive, {} ); // $ExpectError
178+
}
179+
180+
// The compiler throws an error if the `assign` method is provided a fifth argument which is not a function...
181+
{
182+
const x = [ 0, 0, 1, 1, 1 ];
183+
const y = [ false, null, false, null, false, null, false, null, false, null ];
184+
185+
cueveryByRight.assign( x, y, 1, 0, 2 ); // $ExpectError
186+
cueveryByRight.assign( x, y, 1, 0, false ); // $ExpectError
187+
cueveryByRight.assign( x, y, 1, 0, true ); // $ExpectError
188+
cueveryByRight.assign( x, y, 1, 0, 'abc' ); // $ExpectError
189+
cueveryByRight.assign( x, y, 1, 0, void 0 ); // $ExpectError
190+
cueveryByRight.assign( x, y, 1, 0, {} ); // $ExpectError
191+
cueveryByRight.assign( x, y, 1, 0, [] ); // $ExpectError
192+
193+
cueveryByRight.assign( x, y, 1, 0, 2, {} ); // $ExpectError
194+
cueveryByRight.assign( x, y, 1, 0, false, {} ); // $ExpectError
195+
cueveryByRight.assign( x, y, 1, 0, true, {} ); // $ExpectError
196+
cueveryByRight.assign( x, y, 1, 0, 'abc', {} ); // $ExpectError
197+
cueveryByRight.assign( x, y, 1, 0, void 0, {} ); // $ExpectError
198+
cueveryByRight.assign( x, y, 1, 0, {}, {} ); // $ExpectError
199+
cueveryByRight.assign( x, y, 1, 0, [], {} ); // $ExpectError
200+
}
201+
// The compiler throws an error if the `assign` method is provided an unsupported number of arguments...
202+
{
203+
cueveryByRight.assign(); // $ExpectError
204+
cueveryByRight.assign( [] ); // $ExpectError
205+
cueveryByRight.assign( [], [] ); // $ExpectError
206+
cueveryByRight.assign( [], [], 2 ); // $ExpectError
207+
cueveryByRight.assign( [], [], 2, {} ); // $ExpectError
208+
cueveryByRight.assign( [], [], 1, 1, {}, [], {} ); // $ExpectError
209+
}
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
22+
var cueveryByRight = require( './../lib' );
23+
24+
function isPositive( value ) {
25+
return ( value > 0 );
26+
}
27+
28+
// Create an array of random values:
29+
var x = discreteUniform( 10, -10, 10 );
30+
console.log( x );
31+
32+
// Cumulatively test whether every array element passes a test, while iterating from right-to-left:
33+
var out = cueveryByRight( x, isPositive );
34+
console.log( out );

‎base/cuevery-by-right/lib/assign.js

+171
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var arraylike2object = require( './../../../base/arraylike2object' );
24+
25+
26+
// FUNCTIONS //
27+
28+
/**
29+
* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the provided output array.
30+
*
31+
* @private
32+
* @param {Collection} x - input array
33+
* @param {Collection} out - output array
34+
* @param {integer} stride - output array stride
35+
* @param {NonNegativeInteger} offset - output array offset
36+
* @param {Function} predicate - test function
37+
* @param {*} thisArg - execution context
38+
* @returns {Collection} output array
39+
*
40+
* @example
41+
* function fcn( value ) {
42+
* return ( value > 0 );
43+
* }
44+
*
45+
* var x = [ 0, 0, 1, 1, 1 ];
46+
*
47+
* var out = [ 0, 0, 0, 0, 0 ];
48+
* var arr = indexed( x, out, 1, 0, fcn );
49+
* // returns [ true, true, true, false, false ]
50+
*/
51+
function indexed( x, out, stride, offset, predicate, thisArg ) {
52+
var flg;
53+
var io;
54+
var i;
55+
56+
flg = true;
57+
io = offset;
58+
for ( i = x.length - 1; i >= 0; i-- ) {
59+
if ( flg && !predicate.call( thisArg, x[ i ], i, x ) ) {
60+
flg = false;
61+
}
62+
out[ io ] = flg;
63+
io += stride;
64+
}
65+
return out;
66+
}
67+
68+
/**
69+
* Cumulatively tests whether every array element in a provided accessor array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the accessor output array.
70+
*
71+
* @private
72+
* @param {Object} x - input array object
73+
* @param {Object} out - output array object
74+
* @param {integer} stride - output array stride
75+
* @param {NonNegativeInteger} offset - output array offset
76+
* @param {Function} predicate - test function
77+
* @param {*} thisArg - execution context
78+
* @returns {Collection} output array
79+
*
80+
* @example
81+
* function fcn( value ) {
82+
* return ( value > 0 );
83+
* }
84+
*
85+
* var toAccessorArray = require( '@stdlib/array/base/to-accessor-array' );
86+
* var arraylike2object = require( '@stdlib/array/base/arraylike2object' );
87+
*
88+
* var x = toAccessorArray( [ 0, 0, 1, 1, 1 ] );
89+
*
90+
* var out = toAccessorArray( [ 0, 0, 0, 0, 0 ] );
91+
* var arr = accessors( arraylike2object( x ), arraylike2object( out ), 1, 0, fcn );
92+
*
93+
* var v = arr.get( 4 );
94+
* // returns false
95+
*/
96+
function accessors( x, out, stride, offset, predicate, thisArg ) {
97+
var xdata;
98+
var odata;
99+
var xget;
100+
var oset;
101+
var flg;
102+
var io;
103+
var i;
104+
105+
xdata = x.data;
106+
odata = out.data;
107+
108+
xget = x.accessors[ 0 ];
109+
oset = out.accessors[ 1 ];
110+
111+
io = offset;
112+
flg = true;
113+
for ( i = xdata.length - 1; i >= 0; i-- ) {
114+
if ( flg && !predicate.call( thisArg, xget( xdata, i ), i, xdata ) ) {
115+
flg = false;
116+
}
117+
oset( odata, io, flg );
118+
io += stride;
119+
}
120+
return odata;
121+
}
122+
123+
124+
// MAIN //
125+
126+
/**
127+
* Cumulatively tests whether every element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to elements in the output array.
128+
*
129+
* @param {Collection} x - input array
130+
* @param {Collection} out - output array
131+
* @param {integer} stride - output array stride
132+
* @param {NonNegativeInteger} offset - output array offset
133+
* @param {Function} predicate - test function
134+
* @param {*} [thisArg] - execution context
135+
* @returns {Collection} output array
136+
*
137+
* @example
138+
* function fcn( value ) {
139+
* return ( value > 0 );
140+
* }
141+
*
142+
* var x = [ 0, 0, 1, 1 ];
143+
*
144+
* var y = [ false, null, false, null, false, null, false, null ];
145+
* var out = assign( x, y, 2, 0, fcn );
146+
* // returns [ true, null, true, null, false, null, false, null ]
147+
*
148+
* var bool = ( y === out );
149+
* // returns true
150+
*/
151+
function assign( x, out, stride, offset, predicate, thisArg ) {
152+
var xo;
153+
var oo;
154+
155+
xo = arraylike2object( x );
156+
oo = arraylike2object( out );
157+
if (
158+
xo.accessorProtocol ||
159+
oo.accessorProtocol
160+
) {
161+
accessors( xo, oo, stride, offset, predicate, thisArg );
162+
return out;
163+
}
164+
indexed( x, out, stride, offset, predicate, thisArg );
165+
return out;
166+
}
167+
168+
169+
// EXPORTS //
170+
171+
module.exports = assign;

‎base/cuevery-by-right/lib/index.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
/**
22+
* Cumulatively test whether every element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.
23+
*
24+
* @module @stdlib/array/base/cuevery-by-right
25+
*
26+
* @example
27+
* var cueveryByRight = require( '@stdlib/array/base/cuevery-by-right' );
28+
*
29+
* function fcn( value ) {
30+
* return ( value > 0 );
31+
* }
32+
*
33+
* var x = [ 0, 0, 1, 1, 1 ];
34+
*
35+
* var y = cueveryByRight( x, fcn );
36+
* //returns [ true, true, true, false, false ]
37+
*
38+
* @example
39+
* var cueveryByRight = require( '@stdlib/array/base/cuevery-by-right' );
40+
*
41+
* function fcn( value ) {
42+
* return ( value > 0 );
43+
* }
44+
*
45+
* var x = [ 0, 0, 1, 1, 1 ];
46+
*
47+
* var y1 = cueveryByRight( x, fcn );
48+
* // returns [ true, true, true, false, false ]
49+
*
50+
* var y2 = [ false, null, false, null, false, null, false, null, false, null ];
51+
* var out = cueveryByRight.assign( x, y2, 2, 0, fcn );
52+
* // returns [ true, null, true, null, true, null, false, null, false, null ]
53+
*
54+
* var bool = ( out === y2 );
55+
* // returns true
56+
*/
57+
58+
// MODULES //
59+
60+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
61+
var main = require( './main.js' );
62+
var assign = require( './assign.js' );
63+
64+
65+
// MAIN //
66+
67+
setReadOnly( main, 'assign', assign );
68+
69+
70+
// EXPORTS //
71+
72+
module.exports = main;

‎base/cuevery-by-right/lib/main.js

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var filled = require( './../../../base/filled' );
24+
var assign = require( './assign.js' );
25+
26+
27+
// MAIN //
28+
29+
/**
30+
* Cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.
31+
*
32+
* @param {Collection} x - input array
33+
* @param {Function} predicate - test function
34+
* @param {*} [thisArg] - execution context
35+
* @returns {Array} output array
36+
*
37+
* @example
38+
* function fcn( value ) {
39+
* return ( value > 0 );
40+
* }
41+
*
42+
* var x = [ 0, 0, 1, 1, 1 ];
43+
*
44+
* var y = cueveryByRight( x, fcn );
45+
* // returns [ true, true, true, false, false ]
46+
*/
47+
function cueveryByRight( x, predicate, thisArg ) {
48+
var out = filled( false, x.length );
49+
return assign( x, out, 1, 0, predicate, thisArg );
50+
}
51+
52+
53+
// EXPORTS //
54+
55+
module.exports = cueveryByRight;

‎base/cuevery-by-right/package.json

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
{
2+
"name": "@stdlib/array/base/cuevery-by-right",
3+
"version": "0.0.0",
4+
"description": "Cumulatively test whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left.",
5+
"license": "Apache-2.0",
6+
"author": {
7+
"name": "The Stdlib Authors",
8+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
9+
},
10+
"contributors": [
11+
{
12+
"name": "The Stdlib Authors",
13+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
14+
}
15+
],
16+
"main": "./lib",
17+
"directories": {
18+
"benchmark": "./benchmark",
19+
"doc": "./docs",
20+
"example": "./examples",
21+
"lib": "./lib",
22+
"test": "./test"
23+
},
24+
"types": "./docs/types",
25+
"scripts": {},
26+
"homepage": "https://github.com/stdlib-js/stdlib",
27+
"repository": {
28+
"type": "git",
29+
"url": "git://github.com/stdlib-js/stdlib.git"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/stdlib-js/stdlib/issues"
33+
},
34+
"dependencies": {},
35+
"devDependencies": {},
36+
"engines": {
37+
"node": ">=0.10.0",
38+
"npm": ">2.7.0"
39+
},
40+
"os": [
41+
"aix",
42+
"darwin",
43+
"freebsd",
44+
"linux",
45+
"macos",
46+
"openbsd",
47+
"sunos",
48+
"win32",
49+
"windows"
50+
],
51+
"keywords": [
52+
"stdlib",
53+
"stdtypes",
54+
"utils",
55+
"generic",
56+
"array",
57+
"cumulative",
58+
"data",
59+
"structure",
60+
"test",
61+
"predicate",
62+
"all",
63+
"every",
64+
"array.every",
65+
"array-like",
66+
"validate"
67+
]
68+
}
+220
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var Float64Array = require( './../../../float64' );
25+
var toAccessorArray = require( './../../../base/to-accessor-array' );
26+
var cueveryByRight = require( './../lib/assign.js' );
27+
28+
29+
// FUNCTIONS //
30+
31+
function isPositive( v ) {
32+
return v > 0;
33+
}
34+
35+
36+
// TESTS //
37+
38+
tape( 'main export is a function', function test( t ) {
39+
t.ok( true, __filename );
40+
t.strictEqual( typeof cueveryByRight, 'function', 'main export is a function' );
41+
t.end();
42+
});
43+
44+
tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array (generic)', function test( t ) {
45+
var expected;
46+
var actual;
47+
var x;
48+
var y;
49+
50+
x = [ 1, 1, 0, 0, 1 ];
51+
y = [ false, true, false, true, false ];
52+
53+
actual = cueveryByRight( x, y, 1, 0, isPositive );
54+
expected = [ true, false, false, false, false ];
55+
56+
t.strictEqual( actual, y, 'returns expected value' );
57+
t.deepEqual( actual, expected, 'returns expected value' );
58+
59+
x = [ 0, 0, 1, 1 ];
60+
y = [ false, null, false, null, false, null, false, null ];
61+
62+
actual = cueveryByRight( x, y, 2, 0, isPositive );
63+
expected = [ true, null, true, null, false, null, false, null ];
64+
65+
t.strictEqual( actual, y, 'returns expected value' );
66+
t.deepEqual( actual, expected, 'returns expected value' );
67+
68+
x = [ 0, 0, 1, 1, 1 ];
69+
y = [ false, false, false, true, true, true ];
70+
71+
actual = cueveryByRight( x, y, 1, 1, isPositive );
72+
expected = [ false, true, true, true, false, false ];
73+
74+
t.strictEqual( actual, y, 'returns expected value' );
75+
t.deepEqual( actual, expected, 'returns expected value' );
76+
77+
x = [];
78+
y = [ false, false, false, false, false ];
79+
80+
actual = cueveryByRight( x, y, 1, 0, isPositive );
81+
expected = [ false, false, false, false, false ];
82+
83+
t.strictEqual( actual, y, 'returns expected value' );
84+
t.deepEqual( actual, expected, 'returns expected value' );
85+
86+
x = [ 1 ];
87+
y = [ false, false ];
88+
89+
actual = cueveryByRight( x, y, 1, 1, isPositive );
90+
expected = [ false, true ];
91+
92+
t.strictEqual( actual, y, 'returns expected value' );
93+
t.deepEqual( actual, expected, 'returns expected value' );
94+
95+
t.end();
96+
});
97+
98+
tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array (typed)', function test( t ) {
99+
var expected;
100+
var actual;
101+
var x;
102+
var y;
103+
104+
x = new Float64Array( [ 0.0, 1.0, 0.0, 1.0, 1.0 ] );
105+
y = [ false, true, false, true, false ];
106+
107+
actual = cueveryByRight( x, y, 1, 0, isPositive );
108+
expected = [ true, true, false, false, false ];
109+
110+
t.strictEqual( actual, y, 'returns expected value' );
111+
t.deepEqual( actual, expected, 'returns expected value' );
112+
113+
x = new Float64Array( [ 0.0, 0.0, 1.0, 1.0 ] );
114+
y = [ false, null, false, null, false, null, false, null ];
115+
116+
actual = cueveryByRight( x, y, 2, 0, isPositive );
117+
expected = [ true, null, true, null, false, null, false, null ];
118+
119+
t.strictEqual( actual, y, 'returns expected value' );
120+
t.deepEqual( actual, expected, 'returns expected value' );
121+
122+
x = new Float64Array( [ 1.0, 0.0, 0.0, 1.0, 1.0 ] );
123+
y = [ true, false, false, true, true, true ];
124+
125+
actual = cueveryByRight( x, y, 1, 1, isPositive );
126+
expected = [ true, true, true, false, false, false ];
127+
128+
t.strictEqual( actual, y, 'returns expected value' );
129+
t.deepEqual( actual, expected, 'returns expected value' );
130+
131+
x = new Float64Array( [] );
132+
y = [ false, false, false, false, false ];
133+
134+
actual = cueveryByRight( x, y, 1, 0, isPositive );
135+
expected = [ false, false, false, false, false ];
136+
137+
t.strictEqual( actual, y, 'returns expected value' );
138+
t.deepEqual( actual, expected, 'returns expected value' );
139+
140+
x = new Float64Array( [ 1.0 ] );
141+
y = [ false, false ];
142+
143+
actual = cueveryByRight( x, y, 1, 1, isPositive );
144+
expected = [ false, true ];
145+
146+
t.strictEqual( actual, y, 'returns expected value' );
147+
t.deepEqual( actual, expected, 'returns expected value' );
148+
149+
t.end();
150+
});
151+
152+
tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left, and assigns the results to a provided output array ( accessor )', function test( t ) {
153+
var expected;
154+
var actual;
155+
var ybuf;
156+
var x;
157+
var y;
158+
159+
x = toAccessorArray( [ 0, 1, 1, 1, 1 ] );
160+
ybuf = [ false, true, false, true, false ];
161+
y = toAccessorArray( ybuf );
162+
163+
actual = cueveryByRight( x, y, 1, 0, isPositive );
164+
expected = [ true, true, true, true, false ];
165+
166+
t.strictEqual( actual, y, 'returns expected value' );
167+
t.deepEqual( ybuf, expected, 'returns expected value' );
168+
169+
x = toAccessorArray( [ 1, 0, 0, 1 ] );
170+
ybuf = [ false, null, false, null, false, null, false, null ];
171+
y = toAccessorArray( ybuf );
172+
173+
actual = cueveryByRight( x, y, 2, 0, isPositive );
174+
expected = [ true, null, false, null, false, null, false, null ];
175+
176+
t.strictEqual( actual, y, 'returns expected value' );
177+
t.deepEqual( ybuf, expected, 'returns expected value' );
178+
179+
x = toAccessorArray( [ 1, 0, 0, 1, 1 ] );
180+
ybuf = [ true, false, false, false, false, false ];
181+
y = toAccessorArray( ybuf );
182+
183+
actual = cueveryByRight( x, y, 1, 1, isPositive );
184+
expected = [ true, true, true, false, false, false ];
185+
186+
t.strictEqual( actual, y, 'returns expected value' );
187+
t.deepEqual( ybuf, expected, 'returns expected value' );
188+
189+
x = toAccessorArray( [ 1, 1, 1, 1, 0 ] );
190+
ybuf = [ true, true, true, true, true ];
191+
y = toAccessorArray( ybuf );
192+
193+
actual = cueveryByRight( x, y, 1, 0, isPositive );
194+
expected = [ false, false, false, false, false ];
195+
196+
t.strictEqual( actual, y, 'returns expected value' );
197+
t.deepEqual( ybuf, expected, 'returns expected value' );
198+
199+
x = toAccessorArray( [] );
200+
ybuf = [ false, false, false, false, false ];
201+
y = toAccessorArray( ybuf );
202+
203+
actual = cueveryByRight( x, y, 1, 0, isPositive );
204+
expected = [ false, false, false, false, false ];
205+
206+
t.strictEqual( actual, y, 'returns expected value' );
207+
t.deepEqual( ybuf, expected, 'returns expected value' );
208+
209+
x = toAccessorArray( [ 1 ] );
210+
ybuf = [ false, false ];
211+
y = toAccessorArray( ybuf );
212+
213+
actual = cueveryByRight( x, y, 1, 1, isPositive );
214+
expected = [ false, true ];
215+
216+
t.strictEqual( actual, y, 'returns expected value' );
217+
t.deepEqual( ybuf, expected, 'returns expected value' );
218+
219+
t.end();
220+
});

‎base/cuevery-by-right/test/test.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
25+
var hasMethod = require( '@stdlib/assert/is-method' );
26+
var cueveryByRight = require( './../../../base/cuevery-by-right/lib' );
27+
28+
29+
// TESTS //
30+
31+
tape( 'main export is a function', function test( t ) {
32+
t.ok( true, __filename );
33+
t.strictEqual( typeof cueveryByRight, 'function', 'main export is a function' );
34+
t.end();
35+
});
36+
37+
tape( 'attached to the main export is an `assign` method', function test( t ) {
38+
t.strictEqual( hasOwnProp( cueveryByRight, 'assign' ), true, 'returns expected value' );
39+
t.strictEqual( hasMethod( cueveryByRight, 'assign' ), true, 'returns expected value' );
40+
t.end();
41+
});
+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var tape = require( 'tape' );
24+
var Float64Array = require( './../../../float64' );
25+
var toAccessorArray = require( './../../../base/to-accessor-array' );
26+
var cueveryByRight = require( './../../../base/cuevery-by-right/lib' );
27+
28+
29+
// FUNCTIONS //
30+
31+
function isPositive( v ) {
32+
return v > 0;
33+
}
34+
35+
36+
// TESTS //
37+
38+
tape( 'main export is a function', function test( t ) {
39+
t.ok( true, __filename );
40+
t.strictEqual( typeof cueveryByRight, 'function', 'main export is a function' );
41+
t.end();
42+
});
43+
44+
tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (generic)', function test( t ) {
45+
var expected;
46+
var actual;
47+
var x;
48+
49+
function isNotNull( v ) {
50+
return v !== null;
51+
}
52+
x = [ 0, 0, 1, 1, 1 ];
53+
54+
actual = cueveryByRight( x, isPositive );
55+
expected = [ true, true, true, false, false ];
56+
t.deepEqual( actual, expected, 'returns expected value' );
57+
58+
x = [ 1.0, 1.0, 1.0, 0.0, 0.0 ];
59+
actual = cueveryByRight( x, isPositive );
60+
expected = [ false, false, false, false, false ];
61+
t.deepEqual( actual, expected, 'returns expected value' );
62+
63+
x = [ false, true, true, true, true ];
64+
actual = cueveryByRight( x, isPositive );
65+
expected = [ true, true, true, true, false ];
66+
t.deepEqual( actual, expected, 'returns expected value' );
67+
68+
x = [ null, {}, {} ];
69+
actual = cueveryByRight( x, isNotNull );
70+
expected = [ true, true, false ];
71+
t.deepEqual( actual, expected, 'returns expected value' );
72+
73+
t.end();
74+
});
75+
76+
tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (typed)', function test( t ) {
77+
var expected;
78+
var actual;
79+
var x;
80+
81+
x = new Float64Array( [ 0.0, 0.0, 1.0, 0.0, 1.0 ] );
82+
actual = cueveryByRight(x, isPositive);
83+
expected = [ true, false, false, false, false ];
84+
t.deepEqual( actual, expected, 'returns expected value' );
85+
86+
x = new Float64Array( [ 0.0, 0.0, 0.0, 0.0, 0.0 ] );
87+
actual = cueveryByRight( x, isPositive );
88+
expected = [ false, false, false, false, false ];
89+
t.deepEqual( actual, expected, 'returns expected value' );
90+
91+
x = new Float64Array( [ 1.0, 1.0, 1.0, 1.0, 1.0 ] );
92+
actual = cueveryByRight( x, isPositive );
93+
expected = [ true, true, true, true, true ];
94+
95+
t.deepEqual( actual, expected, 'returns expected value' );
96+
97+
x = new Float64Array( [ 1.0, 0.0, 1.0 ] );
98+
actual = cueveryByRight( x, isPositive );
99+
expected = [ true, false, false ];
100+
t.deepEqual( actual, expected, 'returns expected value' );
101+
102+
x = new Float64Array( [ 1.0, 0.0, 1.0, 1.0, 1.0 ] );
103+
actual = cueveryByRight( x, isPositive );
104+
expected = [ true, true, true, false, false ];
105+
t.deepEqual( actual, expected, 'returns expected value' );
106+
107+
t.end();
108+
});
109+
110+
tape( 'the function cumulatively tests whether every array element in a provided array passes a test implemented by a predicate function, while iterating from right-to-left (accessor)', function test( t ) {
111+
var expected;
112+
var actual;
113+
var x;
114+
115+
x = toAccessorArray( [ 0, 0, 1, 1, 1 ] );
116+
117+
actual = cueveryByRight( x, isPositive );
118+
expected = [ true, true, true, false, false ];
119+
t.deepEqual( actual, expected, 'returns expected value' );
120+
121+
x = toAccessorArray( [ 1, 1, 1, 1, 1 ] );
122+
actual = cueveryByRight( x, isPositive );
123+
expected = [ true, true, true, true, true ];
124+
t.deepEqual( actual, expected, 'returns expected value' );
125+
126+
x = toAccessorArray( [ 0, 0, 0, 0, 0 ] );
127+
actual = cueveryByRight( x, isPositive );
128+
expected = [ false, false, false, false, false ];
129+
t.deepEqual( actual, expected, 'returns expected value' );
130+
131+
x = toAccessorArray( [ 1, 1, 0 ] );
132+
actual = cueveryByRight( x, isPositive );
133+
expected = [ false, false, false ];
134+
t.deepEqual( actual, expected, 'returns expected value' );
135+
136+
x = toAccessorArray( [ 0, 1, 1, 1, 1 ] );
137+
actual = cueveryByRight( x, isPositive );
138+
expected = [ true, true, true, true, false ];
139+
t.deepEqual( actual, expected, 'returns expected value' );
140+
t.end();
141+
});

0 commit comments

Comments
 (0)
Please sign in to comment.