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

Skip to content

Commit 3e228f7

Browse files
committed
Auto-generated commit
1 parent fde7dc3 commit 3e228f7

14 files changed

+945
-7
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-14)
7+
## Unreleased (2024-06-16)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`5cd4a70`](https://github.com/stdlib-js/stdlib/commit/5cd4a70beaa7663d2a822b0922b3fb3cc6ec539f) - add `findIndex` and `findLastIndex` methods to `array/bool` [(#2384)](https://github.com/stdlib-js/stdlib/pull/2384)
1314
- [`cba0d92`](https://github.com/stdlib-js/stdlib/commit/cba0d9249a25664a0b52f3ea2fe65eeddedd1e59) - add `find` and `findLast` methods t EDBE o `array/bool` [(#2376)](https://github.com/stdlib-js/stdlib/pull/2376)
1415
- [`d71d044`](https://github.com/stdlib-js/stdlib/commit/d71d04433120ab3096fb01c546d96c60c7684681) - add `sort` method to `array/bool` [(#2363)](https://github.com/stdlib-js/stdlib/pull/2363)
1516
- [`40da309`](https://github.com/stdlib-js/stdlib/commit/40da3097c6ffaed4cd9284d6cdeff8bf11786553) - add `map` method to `array/bool` [(#2292)](https://github.com/stdlib-js/stdlib/pull/2292)
@@ -26,6 +27,7 @@
2627

2728
<details>
2829

30+
- [`5cd4a70`](https://github.com/stdlib-js/stdlib/commit/5cd4a70beaa7663d2a822b0922b3fb3cc6ec539f) - **feat:** add `findIndex` and `findLastIndex` methods to `array/bool` [(#2384)](https://github.com/stdlib-js/stdlib/pull/2384) _(by Jaysukh Makvana, Athan Reines)_
2931
- [`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)_
3032
- [`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)_
3133
- [`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)_

CONTRIBUTORS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Pushpendra Chandravanshi <pushpendrachandravanshi4@gmail.com>
6363
Raunak Kumar Gupta <raunakmodanwal321@gmail.com>
6464
Rejoan Sardar <119718513+Rejoan-Sardar@users.noreply.github.com>
6565
Ricky Reusser <rsreusser@gmail.com>
66+
Ridam Garg <67867319+RidamGarg@users.noreply.github.com>
6667
Robert Gislason <gztown2216@yahoo.com>
6768
Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com>
6869
Rutam <138517416+performant23@users.noreply.github.com>
@@ -75,7 +76,7 @@ Shraddheya Shendre <shendreshraddheya@gmail.com>
7576
Shubh Mehta <93862397+Shubh942@users.noreply.github.com>
7677
Shubham Mishra <shubh622005@gmail.com>
7778
Sivam Das <100067002+Sivam2313@users.noreply.github.com>
78-
Snehil Shah <130062020+Snehil-Shah@users.noreply.github.com>
79+
Snehil Shah <snehilshah.989@gmail.com>
7980
Soumajit Chatterjee <121816890+soumajit23@users.noreply.github.com>
8081
Spandan Barve <contact@marsian.dev>
8182
Stephannie Jiménez Gacha <steff456@hotmail.com>

README.md

Lines changed: 106 additions & 2 deletions
+
var context = {
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ The `predicate` function is provided three arguments:
397397
To set the function execution context, provide a `thisArg`.
398398

399399
```javascript
400-
function predicate( v, i ) {
400+
function predicate( v ) {
401401
this.count += 1;
402402
return ( v === true );
403403
}
@@ -419,6 +419,58 @@ var count = context.count;
419419
// returns 3
420420
```
421421

422+
<a name="method-find-index"></a>
423+
424+
#### BooleanArray.prototype.findIndex( predicate\[, thisArg] )
425+
426+
Returns the index of the first 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.findIndex( predicate );
440+
// returns 0
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 ) {
453+
this.count += 1;
454+
return ( v === true );
455+
}
456+
457+
var arr = new BooleanArray( 3 );
458+
459
460+
'count': 0
461+
};
462+
463+
arr.set( false, 0 );
464+
arr.set( false, 1 );
465+
arr.set( true, 2 );
466+
467+
var z = arr.findIndex( predicate, context );
468+
// returns 2
469+
470+
var count = context.count;
471+
// returns 3
472+
```
473+
422474
<a name="method-find-last"></a>
423475

424476
#### Complex64Array.prototype.findLast( predicate\[, thisArg] )
@@ -449,7 +501,7 @@ The `predicate` function is provided three arguments:
449501
To set the function execution context, provide a `thisArg`.
450502

451503
```javascript
452-
function predicate( v, i ) {
504+
function predicate( v ) {
453505
this.count += 1;
454506
return ( v === true );
455507
}
@@ -471,6 +523,58 @@ var count = context.count;
471523
// returns 3
472524
```
473525

526+
<a name="method-find-last-index"></a>
527+
528+
#### BooleanArray.prototype.findLastIndex( predicate\[, thisArg] )
529+
530+
Returns the index of the last element in an array for which a predicate function returns a truthy value.
531+
532+
```javascript
533+
function predicate( v ) {
534+
return v === true;
535+
}
536+
537+
var arr = new BooleanArray( 3 );
538+
539+
arr.set( true, 0 );
540+
arr.set( false, 1 );
541+
arr.set( true, 2 );
542+
543+
var v = arr.findLastIndex( predicate );
544+
// returns 2
545+
```
546+
547+
The `predicate` function is provided three arguments:
548+
549+
- **value**: current array element.
550+
- **index**: current array element index.
551+
- **arr**: the array on which this method was called.
552+
553+
To set the function execution context, provide a `thisArg`.
554+
555+
```javascript
556+
function predicate( v ) {
557+
this.count += 1;
558+
return ( v === true );
559+
}
560+
561+
var arr = new BooleanArray( 3 );
562+
563+
var context = {
564+
'count': 0
565+
};
566+
567+
arr.set( true, 0 );
568+
arr.set( false, 1 );
569+
arr.set( false, 2 );
570+
571+
var z = arr.findLastIndex( predicate, context );
572+
// returns 0
573+
574+
var count = context.count;
575+
// returns 3
576+
```
577+
474578
<a name="method-get"></a>
475579

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

benchmark/benchmark.find_index.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 isInteger = require( '@stdlib/assert-is-integer' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var BooleanArray = require('./../lib');
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':findIndex', function benchmark( b ) {
32+
var arr;
33+
var idx;
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+
idx = arr.findIndex( predicate );
41+
if ( typeof idx !== 'number' ) {
42+
b.fail( 'should return an integer' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isInteger( idx ) ) {
47+
b.fail( 'should return an integer' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
52+
function predicate( v ) {
53+
return ( v === false );
54+
}
55+
});
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 isInteger = require( '@stdlib/assert-is-integer' ).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 === true );
44+
}
45+
46+
/**
47+
* Creates a benchmark function.
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( 0 ) );
60+
}
61+
arr.push( Boolean( 1 ) );
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 idx;
74+
var i;
75+
76+
b.tic();
77+
for ( i = 0; i < b.iterations; i++ ) {
78+
idx = arr.findIndex( predicate );
79+
if ( typeof idx !== 'number' ) {
80+
b.fail( 'should return an integer' );
81+
}
82+
}
83+
b.toc();
84+
if ( !isInteger( idx ) ) {
85+
b.fail( 'should return an integer' );
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+':findIndex:len='+len, f );
114+
}
115+
}
116+
117+
main();

0 commit comments

Comments
 (0)
0