Skip to content

Commit

Permalink
Auto-generated commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stdlib-bot committed Jun 23, 2024
1 parent 22dad97 commit 7e8ba39
Show file tree
Hide file tree
Showing 8 changed files with 518 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<section class="release" id="unreleased">

## Unreleased (2024-06-22)
## Unreleased (2024-06-23)

<section class="packages">

Expand Down Expand Up @@ -1282,6 +1282,7 @@ This release closes the following issue:

##### Features

- [`fbc42b4`](https://github.com/stdlib-js/stdlib/commit/fbc42b4c66cf695c6c114f64bf3eff65186026f0) - add `includes` method to `array/bool` [(#2441)](https://github.com/stdlib-js/stdlib/pull/2441)
- [`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)
- [`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)
- [`0b3db04`](https://github.com/stdlib-js/stdlib/commit/0b3db0401bd16df7aeccb500d8280c280a394762) - add `toSorted` method to `array/bool` [(#2413)](https://github.com/stdlib-js/stdlib/pull/2413)
Expand Down Expand Up @@ -2255,6 +2256,7 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`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)_
- [`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)_
- [`61c5609`](https://github.com/stdlib-js/stdlib/commit/61c5609ba30f3b07cd97089746a5dca25a614d94) - **docs:** fix examples in REPL documentation for complex number arrays [(#2431)](https://github.com/stdlib-js/stdlib/pull/2431) _(by Jaysukh Makvana)_
- [`4d54abb`](https://github.com/stdlib-js/stdlib/commit/4d54abb0b5e5d2f146e85f2a65799907fbb5bd0c) - **feat:** add boolean dtype support to `array/base/none` [(#2424)](https://github.com/stdlib-js/stdlib/pull/2424) _(by Jaysukh Makvana, Athan Reines)_
Expand Down
22 changes: 22 additions & 0 deletions bool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,28 @@ var v = arr.get( 100 );
// returns undefined
```

<a name="includes"></a>

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

Returns a boolean indicating whether an array includes a provided value.

```javascript
var arr = new BooleanArray( 5 );

arr.set( true, 0 );
arr.set( false, 1 );
arr.set( true, 2 );
arr.set( true, 3 );
arr.set( true, 4 );

var bool = arr.includes( true );
// returns true

bool = arr.includes( false, 2 );
// returns false
```

<a name="method-index-of"></a>

#### BooleanArray.prototype.indexOf( searchElement\[, fromIndex] )
Expand Down
56 changes: 56 additions & 0 deletions bool/benchmark/benchmark.includes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var Boolean = require( '@stdlib/boolean/ctor' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// MAIN //

bench( pkg+':includes', function benchmark( b ) {
var bool;
var arr;
var i;

arr = [];
for ( i = 0; i < 10; i++ ) {
arr.push( Boolean( i%2 ) );
}
arr = new BooleanArray( arr );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = arr.includes( true, 0 );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
});
103 changes: 103 additions & 0 deletions bool/benchmark/benchmark.includes.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @license Apache-2.0
*
* Copyright (c) 2024 The Stdlib Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// MODULES //

var bench = require( '@stdlib/bench' );
var pow = require( '@stdlib/math/base/special/pow' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// FUNCTIONS //

/**
* Creates a benchmark function.
*
* @private
* @param {PositiveInteger} len - array length
* @returns {Function} benchmark function
*/
function createBenchmark( len ) {
var arr;
var i;

arr = [];
for ( i = 0; i < len-1; i++ ) {
arr.push( false );
}
arr.push( true );
arr = new BooleanArray( arr );

return benchmark;

/**
* Benchmark function.
*
* @private
* @param {Benchmark} b - benchmark instance
*/
function benchmark( b ) {
var bool;
var i;

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = arr.includes( true );
if ( typeof bool !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( bool ) ) {
b.fail( 'should return a boolean' );
}
b.pass( 'benchmark finished' );
b.end();
}
}


// MAIN //

/**
* Main execution sequence.
*
* @private
*/
function main() {
var len;
var min;
var max;
var f;
var i;

min = 1; // 10^min
max = 6; // 10^max

for ( i = min; i <= max; i++ ) {
len = pow( 10, i );
f = createBenchmark( len );
bench( pkg+':includes:len='+len, f );
}
}

main();
30 changes: 29 additions & 1 deletion bool/docs/repl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@
<BooleanArray>
> var offset = arr.byteOffset
0
> var buf = new {{alias:@stdlib/array/buffer}}( 240 )
> var buf = new {{alias:@stdlib/array/buffer}}( 240 );
> arr = new {{alias}}( buf, 64 )
<BooleanArray>
> offset = arr.byteOffset
Expand Down Expand Up @@ -484,6 +484,34 @@
true


{{alias}}.prototype.includes( searchElement[, fromIndex] )
Returns a boolean indicating whether an array includes a provided value.

Parameters
----------
searchElement: boolean
Search element.

fromIndex: integer (optional)
Array index at which to start the search. If provided a negative value,
the method resolves the start index relative to the last array element.
Default: 0.

Returns
-------
bool: boolean
Boolean indicating whether an array includes a search element.

Examples
--------
> var arr = new {{alias}}( [ true, false, true, true, true ] )
<BooleanArray>
> var bool = arr.includes( true )
true
> bool = arr.includes( false, 3 )
false


{{alias}}.prototype.indexOf( searchElement[, fromIndex] )
Returns the first index at which a given element can be found.

Expand Down
24 changes: 24 additions & 0 deletions bool/docs/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,30 @@ declare class BooleanArray implements BooleanArrayInterface {
*/
get( i: number ): boolean | void;

/**
* Returns a boolean indicating whether an array includes a provided value.
*
* @param searchElement - element to search for
* @param fromIndex - starting index (inclusive)
* @returns boolean indicating whether an array includes a value
*
* @example
* var arr = new BooleanArray( 5 );
*
* arr.set( true, 0 );
* arr.set( false, 1 );
* arr.set( true, 2 );
* arr.set( true, 3 );
* arr.set( true, 4 );
*
* var bool = arr.includes( true );
* // returns true
*
* bool = arr.includes( false, 2 );
* // returns false
*/
includes( searchElement: boolean, fromIndex?: number ): boolean;

/**
* Returns the first index at which a given element can be found.
*
Expand Down
60 changes: 60 additions & 0 deletions bool/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,66 @@ setReadOnly( BooleanArray.prototype, 'get', function get( idx ) {
return Boolean( this._buffer[ idx ] );
});

/**
* Returns a boolean indicating whether an array includes a provided value.
*
* @name includes
* @memberof BooleanArray.prototype
* @type {Function}
* @param {boolean} searchElement - search element
* @param {integer} [fromIndex=0] - starting index (inclusive)
* @throws {TypeError} `this` must be a boolean array
* @throws {TypeError} first argument must be a boolean value
* @throws {TypeError} second argument must be an integer
* @returns {boolean} boolean indicating whether an array includes a value
*
* @example
* var arr = new BooleanArray( 5 );
*
* arr.set( true, 0 );
* arr.set( false, 1 );
* arr.set( true, 2 );
* arr.set( true, 3 );
* arr.set( true, 4 );
*
* var bool = arr.includes( true );
* // returns true
*
* bool = arr.includes( false, 2 );
* // returns false
*/
setReadOnly( BooleanArray.prototype, 'includes', function includes( searchElement, fromIndex ) {
var buf;
var i;

if ( !isBooleanArray( this ) ) {
throw new TypeError( 'invalid invocation. `this` is not a boolean array.' );
}
if ( !isBoolean( searchElement ) ) {
throw new TypeError( format( 'invalid argument. First argument must be a boolean. Value: `%s`.', searchElement ) );
}
if ( arguments.length > 1 ) {
if ( !isInteger( fromIndex ) ) {
throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) );
}
if ( fromIndex < 0 ) {
fromIndex += this._length;
if ( fromIndex < 0 ) {
fromIndex = 0;
}
}
} else {
fromIndex = 0;
}
buf = this._buffer;
for ( i = fromIndex; i < this._length; i++ ) {
if ( searchElement === Boolean( buf[ i ] ) ) {
return true;
}
}
return false;
});

/**
* Returns the first index at which a given element can be found.
*
Expand Down
Loading

0 comments on commit 7e8ba39

Please sign in to comment.