8000 Auto-generated commit · stdlib-js/array-bool@fde7dc3 · GitHub
[go: up one dir, main page]

Skip to content

Commit fde7dc3

Browse files
committed
Auto-generated commit
1 parent 136846f commit fde7dc3

12 files changed

+983
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-06-12)
7+
## Unreleased (2024-06-14)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`cba0d92`](https://github.com/stdlib-js/stdlib/commit/cba0d9249a25664a0b52f3ea2fe65eeddedd1e59) - add `find` and `findLast` methods to `array/bool` [(#2376)](https://github.com/stdlib-js/stdlib/pull/2376)
1314
- [`d71d044`](https://github.com/stdlib-js/stdlib/commit/d71d04433120ab3096fb01c546d96c60c7684681) - add `sort` method to `array/bool` [(#2363)](https://github.com/stdlib-js/stdlib/pull/2363)
1415
- [`40da309`](https://github.com/stdlib-js/stdlib/commit/40da3097c6ffaed4cd9284d6cdeff8bf11786553) - add `map` method to `array/bool` [(#2292)](https://github.com/stdlib-js/stdlib/pull/2292)
1516
- [`5d53c2d`](https://github.com/stdlib-js/stdlib/commit/5d53c2de22e6899dc3970b4714c0c4e228562f92) - add initial TypeScript declarations
@@ -25,6 +26,7 @@
2526

2627
<details>
2728

29+
- [`cba0d92`](https://github.com/stdlib-js/stdlib/commit/cba0d9249a25664a0b52f3ea2fe65eeddedd1e59) - **feat:** add `find` and `findLast` methods to `array/bool` [(#2376)](https://github.com/stdlib-js/stdlib/pull/2376) _(by Jaysukh Makvana)_
2830
- [`d71d044`](https://github.com/stdlib-js/stdlib/commit/d71d04433120ab3096fb01c546d96c60c7684681) - **feat:** add `sort` method to `array/bool` [(#2363)](https://github.com/stdlib-js/stdlib/pull/2363) _(by Jaysukh Makvana)_
2931
- [`1b5abe6`](https://github.com/stdlib-js/stdlib/commit/1b5abe6cb97ca371aeeae5ef5e39e9ef20898e52) - **chore:** update package meta data [(#2344)](https://github.com/stdlib-js/stdlib/pull/2344) _(by stdlib-bot, Athan Reines)_
3032
- [`40da309`](https://github.com/stdlib-js/stdlib/commit/40da3097c6ffaed4cd9284d6cdeff8bf11786553) - **feat:** add `map` method to `array/bool` [(#2292)](https://github.com/stdlib-js/stdlib/pull/2292) _(by Jaysukh Makvana, Athan Reines)_

README.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,110 @@ var len = arr.length;
367367
// returns 4
368368
```
369369

370+
<a name="method-find"></a>
371+
372+
#### BooleanArray.prototype.find( predicate\[, thisArg] )
373+
374+
Returns the first element in an array for which a predicate function returns a truthy value.
375+
376+
```javascript
377+
function predicate( v ) {
378+
return v === true;
379+
}
380+
381+
var arr = new BooleanArray( 3 );
382+
383+
arr.set( true, 0 );
384+
arr.set( false, 1 );
385+
arr.set( true, 2 );
386+
387+
var v = arr.find( predicate );
388+
// returns true
389+
```
390+
391+
The `predicate` function is provided three arguments:
392+
393+
- **value**: current array element.
394+
- **index**: current array element index.
395+
- **arr**: the array on which this method was called.
396+
397+
To set the function execution context, provide a `thisArg`.
398+
399+
```javascript
400+
function predicate( v, i ) {
401+
this.count += 1;
402+
return ( v === true );
403+
}
404+
405+
var arr = new BooleanArray( 3 );
406+
407+
var context = {
408+
'count': 0
409+
};
410+
411+
arr.set( false, 0 );
412+
arr.set( false, 1 );
413+
arr.set( true, 2 );
414+
415+
var z = arr.find( predicate, context );
416+
// returns true
417+
418+
var count = context.count;
419+
// returns 3
420+
```
421+
422+
<a name="method-find-last"></a>
423+
424+
#### Complex64Array.prototype.findLast( predicate\[, thisArg] )
425+
426+
Returns the last element in an array for which a predicate function returns a truthy value.
427+
428+
```javascript
429+
function predicate( v ) {
430+
return v === true;
431+
}
432+
433+
var arr = new BooleanArray( 3 );
434+
435+
arr.set( true, 0 );
436+
arr.set( false, 1 );
437+
arr.set( true, 2 );
438+
439+
var v = arr.findLast( predicate );
440+
// returns true
441+
```
442+
443+
The `predicate` function is provided three arguments:
444+
445+
- **value**: current array element.
446+
- **index**: current array element index.
447+
- **arr**: the array on which this method was called.
448+
449+
To set the function execution context, provide a `thisArg`.
450+
451+
```javascript
452+
function predicate( v, i ) {
453+
this.count += 1;
454+
re 10000 turn ( v === true );
455+
}
456+
457+
var arr = new BooleanArray( 3 );
458+
459+
var context = {
460+
'count': 0
461+
};
462+
463+
arr.set( true, 0 );
464+
arr.set( false, 1 );
465+
arr.set( false, 2 );
466+
467+
var z = arr.findLast( predicate, context );
468+
// returns true
469+
470+
var count = context.count;
471+
// returns 3
472+
```
473+
370474
<a name="method-get"></a>
371475

372476
#### BooleanArray.prototype.get( i )

benchmark/benchmark.find.js

Lines changed: 55 additions & 0 deletions
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 bench = require( '@stdlib/bench-harness' );
24+
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var BooleanArray = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':find', function benchmark( b ) {
32+
var arr;
33+
var v;
34+
var i;
35+
36+
arr = new BooleanArray( [ true, false, false, true, true, false ] );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
v = arr.find( predicate );
41+
if ( typeof v !== 'boolean' ) {
42+
b.fail( 'should return a boolean' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBoolean( v ) ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
52+
function predicate( v ) {
53+
return ( v === false );
54+
}
55+
});

benchmark/benchmark.find.length.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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-harness' );
24+
var pow = require( '@stdlib/math-base-special-pow' );
25+
var Boolean = require( '@stdlib/boolean-ctor' );
26+
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
27+
var pkg = require( './../package.json' ).name;
28+
var BooleanArray = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Predicate function.
35+
*
36+
* @private
37+
* @param {boolean} value - array element
38+
* @param {NonNegativeInteger} idx - array element index
39+
* @param {BooleanArray} arr - array instance
40+
* @returns {boolean} boolean indicating whether a value passes a test
41+
*/
42+
function predicate( value ) {
43+
return ( value === false );
44+
}
45+
46+
/**
47+
* Creates a benchmark function.< 10000 /span>
48+
*
49+
* @private
50+
* @param {PositiveInteger} len - array length
51+
* @returns {Function} benchmark function
52+
*/
53+
function createBenchmark( len ) {
54+
var arr;
55+
var i;
56+
57+
arr = [];
58+
for ( i = 0; i < len-1; i++ ) {
59+
arr.push( Boolean( 1 ) );
60+
}
61+
arr.push( Boolean( 0 ) );
62+
arr = new BooleanArray( arr );
63+
64+
return benchmark;
65+
66+
/**
67+
* Benchmark function.
68+
*
69+
* @private
70+
* @param {Benchmark} b - benchmark instance
71+
*/
72+
function benchmark( b ) {
73+
var v;
74+
var i;
75+
76+
b.tic();
77+
for ( i = 0; i < b.iterations; i++ ) {
78+
v = arr.find( predicate );
79+
if ( typeof v !== 'boolean' ) {
80+
b.fail( 'should return a boolean' );
81+
}
82+
}
83+
b.toc();
84+
if ( !isBoolean( v ) ) {
85+
b.fail( 'should return a boolean' );
86+
}
87+
b.pass( 'benchmark finished' );
88+
b.end();
89+
}
90+
}
91+
92+
93+
// MAIN //
94+
95+
/**
96+
* Main execution sequence.
97+
*
98+
* @private
99+
*/
100+
function main() {
101+
var len;
102+
var min;
103+
var max;
104+
var f;
105+
var i;
106+
107+
min = 1; // 10^min
108+
max = 6; // 10^max
109+
110+
for ( i = min; i <= max; i++ ) {
111+
len = pow( 10, i );
112+
f = createBenchmark( len );
113+
bench( pkg+':find:len='+len, f );
114+
}
115+
}
116+
117+
main();

benchmark/benchmark.find_last.js

Lines changed: 55 additions & 0 deletions
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 bench = require( '@stdlib/bench-harness' );
24+
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var BooleanArray = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':findLast', function benchmark( b ) {
32+
var arr;
33+
var v;
34+
var i;
35+
36+
arr = new BooleanArray( [ true, false, false, true, true, false ] );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
v = arr.findLast( predicate );
41+
if ( typeof v !== 'boolean' ) {
42+
b.fail( 'should return a boolean' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBoolean( v ) ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
52+
function predicate( v ) {
53+
return ( v === false );
54+
}
55+
});

0 commit comments

Comments
 (0)
0