Skip to content

Commit 1250506

Browse files
committed
Auto-generated commit
1 parent 8d5dd04 commit 1250506

File tree

16 files changed

+1878
-2
lines changed

16 files changed

+1878
-2
lines changed

CHANGELOG.md

Lines changed: 26 additions & 2 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-22)
7+
## Unreleased (2024-09-23)
88

99
<section class="packages">
1010

@@ -188,6 +188,28 @@
188188

189189
<!-- /.package -->
190190

191+
<section class="package" id="array-base-cusome-unreleased">
192+
193+
#### [@stdlib/array/base/cusome](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/cusome)
194+
195+
<details>
196+
197+
<section class="features">
198+
199+
##### Features
200+
201+
- [`2091d38`](https://github.com/stdlib-js/stdlib/commit/2091d38aec245202fe1bbff462b12d0f5ed54ee1) - add `array/base/cusome`
202+
203+
</section>
204+
205+
<!-- /.features -->
206+
207+
</details>
208+
209+
</section>
210+
211+
<!-- /.package -->
212+
191213
<section class="package" id="array-base-cusome-by-right-unreleased">
192214

193215
#### [@stdlib/array/base/cusome-by-right](https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/array/base/cusome-by-right)
@@ -382,13 +404,14 @@
382404

383405
### Contributors
384406

385-
A total of 5 people contributed to this release. Thank you to the following contributors:
407+
A total of 6 people contributed to this release. Thank you to the following contributors:
386408

387409
- Athan Reines
388410
- HarshaNP
389411
- Kaif Mohd
390412
- Philipp Burckhardt
391413
- Vaibhav Patel
414+
- yaswanth
392415

393416
</section>
394417

@@ -400,6 +423,7 @@ A total of 5 people contributed to this release. Thank you to the following cont
400423

401424
<details>
402425

426+
- [`2091d38`](https://github.com/stdlib-js/stdlib/commit/2091d38aec245202fe1bbff462b12d0f5ed54ee1) - **feat:** add `array/base/cusome` _(by yaswanth, Philipp Burckhardt)_
403427
- [`43aa58f`](https://github.com/stdlib-js/stdlib/commit/43aa58f81dcad604f11a5715a1546c015b0a9623) - **feat:** add `isByteOrder` to namespace _(by Athan Reines)_
404428
- [`b18478e`](https://github.com/stdlib-js/stdlib/commit/b18478e236e9cb6991d5a0f952d217e043e46587) - **feat:** add `array/base/assert/is-byte-order` _(by Athan Reines)_
405429
- [`444e453`](https://github.com/stdlib-js/stdlib/commit/444e45363e751ab85736bc97b642520c3e5db301) - **feat:** add `byteOrders` to namespace _(by Athan Reines)_

base/cusome/README.md

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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+
# cusome
22+
23+
> Cumulatively test whether at least `n` array elements in a provided array are truthy.
24+
25+
<section class="usage">
26+
27+
## Usage
28+
29+
```javascript
30+
var cusome = require( '@stdlib/array/base/cusome' );
31+
```
32+
33+
#### cusome( x, n )
34+
35+
Cumulatively tests whether at least `n` array elements in a provided array are truthy.
36+
37+
```javascript
38+
var x = [ false, false, false, true, true ];
39+
40+
var y = cusome( x, 2 );
41+
// returns [ false, false, false, false, true ];
42+
```
43+
44+
#### cusome.assign( x, n, y, stride, offset )
45+
46+
Cumulatively tests whether at least `n` array elements in a provided array are truthy and assigns results to a provided output array.
47+
48+
```javascript
49+
var x = [ false, false, false, true, true ];
50+
var y = [ false, null, false, null, false, null, false, null, false, null ];
51+
52+
var out = cusome.assign( x, 2, y, 2, 0 );
53+
// returns [ false, null, false, null, false, null, false, null, true, null ]
54+
55+
var bool = ( out === y );
56+
// returns true
57+
```
58+
59+
The function supports the following parameters:
60+
61+
- **x**: input array.
62+
- **n**: number of elements.
63+
- **out**: output array.
64+
- **stride**: output array stride.
65+
- **offset**: output array offset.
66+
67+
</section>
68+
69+
<!-- /.usage -->
70+
71+
<section class="notes">
72+
73+
</section>
74+
75+
<!-- /.notes -->
76+
77+
<section class="examples">
78+
79+
## Examples
80+
81+
<!-- eslint no-undef: "error" -->
82+
83+
```javascript
84+
var bernoulli = require( '@stdlib/random/array/bernoulli' );
85+
var cusome = require( '@stdlib/array/base/cusome' );
86+
87+
// Create an array of random values:
88+
var x = bernoulli( 10, 0.3 );
89+
console.log( x );
90+
91+
// Cumulatively test whether at least two array elements are truthy:
92+
var out = cusome( x, 2 );
93+
console.log( out );
94+
```
95+
96+
</section>
97+
98+
<!-- /.examples -->
99+
100+
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
101+
102+
<section class="related">
103+
104+
</section>
105+
106+
<!-- /.related -->
107+
108+
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
109+
110+
<section class="links">
111+
112+
</section>
113+
114+
<!-- /.links -->
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 filled = require( './../../../base/filled' );
27+
var pkg = require( './../package.json' ).name;
28+
var cusome = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var x = filled( 0, len );
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var y;
52+
var v;
53+
var i;
54+
55+
y = filled( true, len );
56+
57+
b.tic();
58+
for ( i = 0; i < b.iterations; i++ ) {
59+
v = cusome.assign( x, 2, y, 1, 0 );
60+
if ( typeof v !== 'object' ) {
61+
b.fail( 'should return an array' );
62+
}
63+
}
64+
b.toc();
65+
if ( !isArray( v ) ) {
66+
b.fail( 'should return an array' );
67+
}
68+
b.pass( 'benchmark finished' );
69+
b.end();
70+
}
71+
}
72+
73+
74+
// MAIN //
75+
76+
/**
77+
* Main execution sequence.
78+
*
79+
* @private
80+
*/
81+
function main() {
82+
var len;
83+
var min;
84+
var max;
85+
var f;
86+
var i;
87+
88+
min = 1; // 10^min
89+
max = 6; // 10^max
90+
91+
for ( i = min; i <= max; i++ ) {
92+
len = pow( 10, i );
93+
f = createBenchmark( len );
94+
bench( pkg+':assign:len='+len, f );
95+
}
96+
}
97+
98+
main();

base/cusome/benchmark/benchmark.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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 pkg = require( './../package.json' ).name;
26+
var cusome = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg, function benchmark( b ) {
32+
var x;
33+
var i;
34+
var v;
35+
36+
x = [ false, false, true, false, false ];
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
v = cusome( x, 2 );
41+
if ( typeof v !== 'object' ) {
42+
b.fail( 'should return an array' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isArray( v ) ) {
47+
b.fail( 'should return an array' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});

0 commit comments

Comments
 (0)