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

Skip to content

Commit 4aa1ce2

Browse files
committed
Auto-generated commit
1 parent 7946248 commit 4aa1ce2

10 files changed

+521
-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-22)
7+
## Unreleased (2024-06-23)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`fbc42b4`](https://github.com/stdlib-js/stdlib/commit/fbc42b4c66cf695c6c114f64bf3eff65186026f0) - add `includes` method to `array/bool` [(#2441)](https://github.com/stdlib-js/stdlib/pull/2441)
1314
- [`c58e9e4`](https://github.com/stdlib-js/stdlib/commit/c58e9e4dce4361b4ae7454eca926b0e00afb15aa) - add `indexOf` and `lastIndexOf` methods to `array/bool` [(#2432)](https://github.com/stdlib-js/stdlib/pull/2432)
1415
- [`42c67e7`](https://github.com/stdlib-js/stdlib/commit/42c67e76cdf919e4e43ff9333d9acc6177eb5558) - add `every` and `some` methods to `array/bool` [(#2421)](https://github.com/stdlib-js/stdlib/pull/2421)
1516
- [`0b3db04`](https://github.com/stdlib-js/stdlib/commit/0b3db0401bd16df7aeccb500d8280c280a394762) - add `toSorted` method to `array/bool` [(#2413)](https://github.com/stdlib-js/stdlib/pull/2413)
@@ -24,6 +25,7 @@
2425

2526
<details>
2627

28+
- [`fbc42b4`](https://github.com/stdlib-js/stdlib/commit/fbc42b4c66cf695c6c114f64bf3eff65186026f0) - **feat:** add `includes` method to `array/bool` [(#2441)](https://github.com/stdlib-js/stdlib/pull/2441) _(by Jaysukh Makvana)_
2729
- [`c58e9e4`](https://github.com/stdlib-js/stdlib/commit/c58e9e4dce4361b4ae7454eca926b0e00afb15aa) - **feat:** add `indexOf` and `lastIndexOf` methods to `array/bool` [(#2432)](https://github.com/stdlib-js/stdlib/pull/2432) _(by Jaysukh Makvana, Athan Reines)_
2830
- [`42c67e7`](https://github.com/stdlib-js/stdlib/commit/42c67e76cdf919e4e43ff9333d9acc6177eb5558) - **feat:** add `every` and `some` methods to `array/bool` [(#2421)](https://github.com/stdlib-js/stdlib/pull/2421) _(by Jaysukh Makvana, Athan Reines)_
2931
- [`0b3db04`](https://github.com/stdlib-js/stdlib/commit/0b3db0401bd16df7aeccb500d8280c280a394762) - **feat:** add `toSorted` method to `array/bool` [(#2413)](https://github.com/stdlib-js/stdlib/pull/2413) _(by Jaysukh Makvana)_

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,28 @@ var v = arr.get( 100 );
653653
// returns undefined
654654
```
655655

656+
<a name="includes"></a>
657+
658+
#### BooleanArray.prototype.includes( searchElement\[, fromIndex] )
659+
660+
Returns a boolean indicating whether an array includes a provided value.
661+
662+
```javascript
663+
var arr = new BooleanArray( 5 );
664+
665+
arr.set( true, 0 );
666+
arr.set( false, 1 );
667+
arr.set( true, 2 );
668+
arr.set( true, 3 );
669+
arr.set( true, 4 );
670+
671+
var bool = arr.includes( true );
672+
// returns true
673+
674+
bool = arr.includes( false, 2 );
675+
// returns false
676+
```
677+
656678
<a name="method-index-of"></a>
657679

658680
#### BooleanArray.prototype.indexOf( searchElement\[, fromIndex] )

benchmark/benchmark.includes.js

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

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/repl.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@
257257
<BooleanArray>
258258
> var offset = arr.byteOffset
259259
0
260-
> var buf = new {{alias:@stdlib/array/buffer}}( 240 )
260+
> var buf = new {{alias:@stdlib/array/buffer}}( 240 );
261261
> arr = new {{alias}}( buf, 64 )
262262
<BooleanArray>
263263
> offset = arr.byteOffset
@@ -484,6 +484,34 @@
484484
true
485485

486486

487+
{{alias}}.prototype.includes( searchElement[, fromIndex] )
488+
Returns a boolean indicating whether an array includes a provided value.
489+
490+
Parameters
491+
----------
492+
searchElement: boolean
493+
Search element.
494+
495+
fromIndex: integer (optional)
496+
Array index at which to start the search. If provided a negative value,
497+
the method resolves the start index relative to the last array element.
498+
Default: 0.
499+
500+
Returns
501+
-------
502+
bool: boolean
503+
Boolean indicating whether an array includes a search element.
504+
505+
Examples
506+
--------
507+
> var arr = new {{alias}}( [ true, false, true, true, true ] )
508+
<BooleanArray>
509+
> var bool = arr.includes( true )
510+
true
511+
> bool = arr.includes( false, 3 )
512+
false
513+
514+
487515
{{alias}}.prototype.indexOf( searchElement[, fromIndex] )
488516
Returns the first index at which a given element can be found.
489517

docs/types/index.d.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,30 @@ declare class BooleanArray implements BooleanArrayInterface {
406406
*/
407407
get( i: number ): boolean | void;
408408

409+
/**
410+
* Returns a boolean indicating whether an array includes a provided value.
411+
*
412+
* @param searchElement - element to search for
413+
* @param fromIndex - starting index (inclusive)
414+
* @returns boolean indicating whether an array includes a value
415+
*
416+
* @example
417+
* var arr = new BooleanArray( 5 );
418+
*
419+
* arr.set( true, 0 );
420+
* arr.set( false, 1 );
421+
* arr.set( true, 2 );
422+
* arr.set( true, 3 );
423+
* arr.set( true, 4 );
424+
*
425+
* var bool = arr.includes( true );
426+
* // returns true
427+
*
428+
* bool = arr.includes( false, 2 );
429+
* // returns false
430+
*/
431+
includes( searchElement: boolean, fromIndex?: number ): boolean;
432+
409433
/**
410434
* Returns the first index at which a given element can be found.
411435
*

lib/main.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,66 @@ setReadOnly( BooleanArray.prototype, 'get', function get( idx ) {
720720
return Boolean( this._buffer[ idx ] );
721721
});
722722

723+
/**
724+
* Returns a boolean indicating whether an array includes a provided value.
725+
*
726+
* @name includes
727+
* @memberof BooleanArray.prototype
728+
* @type {Function}
729+
* @param {boolean} searchElement - search element
730+
* @param {integer} [fromIndex=0] - starting index (inclusive)
731+
* @throws {TypeError} `this` must be a boolean array
732+
* @throws {TypeError} first argument must be a boolean value
733+
* @throws {TypeError} second argument must be an integer
734+
* @returns {boolean} boolean indicating whether an array includes a value
735+
*
736+
* @example
737+
* var arr = new BooleanArray( 5 );
738+
*
739+
* arr.set( true, 0 );
740+
* arr.set( false, 1 );
741+
* arr.set( true, 2 );
742+
* arr.set( true, 3 );
743+
* arr.set( true, 4 );
744+
*
745+
* var bool = arr.includes( true );
746+
* // returns true
747+
*
748+
* bool = arr.includes( false, 2 );
749+
* // returns false
750+
*/
751+
setReadOnly( BooleanArray.prototype, 'includes', function includes( searchElement, fromIndex ) {
752+
var buf;
753+
var i;
754+
755+
if ( !isBooleanArray( this ) ) {
756+
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
757+
}
758+
if ( !isBoolean( searchElement ) ) {
759+
throw new TypeError( format( 'invalid argument. First argument must be a boolean. Value: `%s`.', searchElement ) );
760+
}
761+
if ( arguments.length > 1 ) {
762+
if ( !isInteger( fromIndex ) ) {
763+
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
764+
}
765+
if ( fromIndex < 0 ) {
766+
fromIndex += this._length;
767+
if ( fromIndex < 0 ) {
768+
fromIndex = 0;
769+
}
770+
}
771+
} else {
772+
fromIndex = 0;
773+
}
774+
buf = this._buffer;
775+
for ( i = fromIndex; i < this._length; i++ ) {
776+
if ( searchElement === Boolean( buf[ i ] ) ) {
777+
return true;
778+
}
779+
}
780+
return false;
781+
});
782+
723783
/**
724784
* Returns the first index at which a given element can be found.
725785
*

0 commit comments

Comments
 (0)
0