Skip to content

Commit aa5dbe3

Browse files
committed
Auto-generated commit
1 parent 587f3db commit aa5dbe3

File tree

16 files changed

+1803
-4
lines changed

16 files changed

+1803
-4
lines changed

CHANGELOG.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-09-28)
7+
## Unreleased (2024-09-29)
88

99
<section class="packages">
1010

@@ -291,6 +291,40 @@ This release closes the following issue:
291291

292292
<!-- /.package -->
293293

294+
<section class="package" id="array-base-cusome-by-unreleased">
295+
296+
#### [@stdlib/array/base/cusome-by](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/cusome-by)
297+
298+
<details>
299+
300+
<section class="features">
301+
302+
##### Features
303+
304+
- [`9835dae`](https://github.com/stdlib-js/stdlib/commit/9835dae5a4dba0aae50d8582b97ad69d17fefe6d) - add `array/base/cusome-by` [(#2953)](https://github.com/stdlib-js/stdlib/pull/2953)
305+
306+
</section>
307+
308+
<!-- /.features -->
309+
310+
<section class="issues">
311+
312+
##### Closed Issues
313+
314+
This release closes the following issue:
315+
316+
[#2326](https://github.com/stdlib-js/stdlib/issues/2326)
317+
318+
</section>
319+
320+
<!-- /.issues -->
321+
322+
</details>
323+
324+
</section>
325+
326+
<!-- /.package -->
327+
294328
<section class="package" id="array-base-cusome-by-right-unreleased">
295329

296330
#### [@stdlib/array/base/cusome-by-right](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/cusome-by-right)
@@ -617,9 +651,9 @@ This release closes the following issue:
617651

618652
### Closed Issues
619653

620-
This release closes the following issue:
654+
A total of 2 issues were closed in this release:
621655

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

624658
</section>
625659

@@ -629,8 +663,9 @@ This release closes the following issue:
629663

630664
### Contributors
631665

632-
A total of 7 people contributed to this release. Thank you to the following contributors:
666+
A total of 8 people contributed to this release. Thank you to the following contributors:
633667

668+
- Aditya Sapra
634669
- Athan Reines
635670
- Debashis Maharana
636671
- HarshaNP
@@ -649,6 +684,7 @@ A total of 7 people contributed to this release. Thank you to the following cont
649684

650685
<details>
651686

687+
- [`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)_
652688
- [`abf0407`](https://github.com/stdlib-js/stdlib/commit/abf040787f6598438b0100a729a8331b7f80f62f) - **chore:** resolve lint errors in TS files _(by Philipp Burckhardt)_
653689
- [`7f368f6`](https://github.com/stdlib-js/stdlib/commit/7f368f6c3f4cea444a304a62616cea36a5f143eb) - **fix:** remove unused imports from TS declaration file _(by Philipp Burckhardt)_
654690
- [`975147f`](https://github.com/stdlib-js/stdlib/commit/975147f3125c786ec1672acb3d2564ca16eaa790) - **docs:** fix TSDoc lint errors _(by Philipp Burckhardt)_

base/cusome-by/README.md

Lines changed: 145 additions & 0 deletions
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+
# cusomeBy
22+
23+
> Cumulatively test whether at least `n` array elements in a provided array pass a test implemented by a predicate function.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var cusomeBy = require( '@stdlib/array/base/cusome-by' );
31+
```
32+
33+
#### cusomeBy( x, n, predicate\[, thisArg ] )
34+
35+
Cumulatively tests whether at least `n` array elements in a provided array pass a test implemented by a predicate function.
36+
37+
```javascript
38+
function fcn( value) {
39+
return ( value > 0 );
40+
}
41+
42+
var x = [ 0, 0, 0, 1, 1 ];
43+
44+
var y = cusomeBy( x, 2, fcn );
45+
// returns [ false, false, false , false, true ]
46+
```
47+
48+
The invoked `predicate` function is provided three arguments:
49+
50+
- **value**: collection element.
51+
- **index**: collection index.
52+
- **collection**: input collection.
53+
54+
To set the function execution context, provide a `thisArg`.
55+
56+
```javascript
57+
function fcn( v ) {
58+
this.count += 1;
59+
return ( v > 0 );
60+
}
61+
62+
var x = [ 0, 0, 0, 1, 1 ];
63+
64+
var context = {
65+
'count': 0
66+
};
67+
68+
var bool = cusomeBy( x, 1, fcn, context );
69+
// returns [ false, false, false, true, true ]
70+
71+
var count = context.count;
72+
// returns 4
73+
```
74+
75+
#### cusomeBy.assign( x, n, out, stride, offset, predicate\[, thisArg ] )
76+
77+
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.
78+
79+
```javascript
80+
function fcn( v ) {
81+
return ( v > 0 );
82+
}
83+
84+
var x = [ 0, 0, 0, 1, 1 ];
85+
var y = [ false, null, false, null, false, null, false, null, false, null ];
86+
87+
var out = cusomeBy.assign( x, 2, y, 2, 0, fcn );
88+
// returns [ false, null, false, null, false, null, false, null, true, null ]
89+
90+
var bool = ( out === y );
91+
// returns true
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 bernoulli = require( '@stdlib/random/array/bernoulli' );
112+
var cusomeBy = require( '@stdlib/array/base/cusome-by' );
113+
114+
function fcn( value ) {
115+
return ( value > 0 );
116+
}
117+
118+
// Create an array of random values:
119+
var x = bernoulli( 10, 0.8 );
120+
console.log( x );
121+
122+
// Cumulatively test whether at least three array elements are positive:
123+
var y = cusomeBy( x, 3, fcn );
124+
console.log( y );
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 -->
Lines changed: 99 additions & 0 deletions
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 cusomeBy = 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 = cusomeBy.assign( x, 2, 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();

base/cusome-by/benchmark/benchmark.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 zeroTo = require( './../../../base/zero-to' );
26+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
27+
var pkg = require( './../package.json' ).name;
28+
var cusomeBy = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg+'::copy:len=100', function benchmark( b ) {
34+
var x;
35+
var i;
36+
var v;
37+
38+
x = zeroTo( 100 );
39+
40+
b.tic();
41+
for ( i = 0; i < b.iterations; i++ ) {
42+
v = cusomeBy( x, 50, isPositiveInteger );
43+
if ( typeof v !== 'object' ) {
44+
b.fail( 'should return an array' );
45+
}
46+
}
47+
b.toc();
48+
if ( !isArray( v ) ) {
49+
b.fail( 'should return an array' );
50+
}
51+
b.pass( 'benchmark finished' );
52+
b.end();
53+
});

0 commit comments

Comments
 (0)