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 21, 2024
1 parent e3b5d48 commit 88b80eb
Show file tree
Hide file tree
Showing 11 changed files with 1,020 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ This release closes the following issue:

##### Features

- [`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)
- [`de50d0a`](https://github.com/stdlib-js/stdlib/commit/de50d0af5f4b9a466a87be81da737fdbed48dbf3) - add `reverse` and `toReversed` methods to `array/bool` [(#2390)](https://github.com/stdlib-js/stdlib/pull/2390)
- [`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)
Expand Down Expand Up @@ -2163,6 +2164,7 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`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)_
- [`d301be9`](https://github.com/stdlib-js/stdlib/commit/d301be9e2cabe07efe219c00d10aebd15e0673e7) - **fix:** ensure support for real-to-complex casting in boolean and mask array indexing _(by Athan Reines)_
- [`0b727a5`](https://github.com/stdlib-js/stdlib/commit/0b727a5d922225d23693e456b5f7b5b82f63750a) - **feat:** add `mskput` to namespace _(by Athan Reines)_
- [`201ce11`](https://github.com/stdlib-js/stdlib/commit/201ce11a0985502cfc82891fda3fe3b2d656afef) - **feat:** add `array/mskput` _(by Athan Reines)_
Expand Down
104 changes: 104 additions & 0 deletions bool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,58 @@ var len = arr.length;
// returns 4
```

<a name="method-every"></a>

#### BooleanArray.prototype.every( predicate\[, thisArg] )

Returns a boolean indicating whether all elements pass a test.

```javascript
function predicate( v ) {
return v === true;
}

var arr = new BooleanArray( 3 );

arr.set( true, 0 );
arr.set( true, 1 );
arr.set( true, 2 );

var bool = arr.every( predicate );
// returns true
```

The `predicate` function is provided three arguments:

- **value**: current array element.
- **index**: current array element index.
- **arr**: the array on which this method was called.

To set the function execution context, provide a `thisArg`.

```javascript
function predicate( v ) {
this.count += 1;
return v === true;
}

var arr = new BooleanArray( 3 );

var context = {
'count': 0
};

arr.set( true, 0 );
arr.set( true, 1 );
arr.set( true, 2 );

var bool = arr.every( predicate, context );
// returns true

var count = context.count;
// returns 3
```

<a name="method-find"></a>

#### BooleanArray.prototype.find( predicate\[, thisArg] )
Expand Down Expand Up @@ -715,6 +767,58 @@ A few notes:
- If a target array cannot accommodate all values (i.e., the length of source array plus `i` exceeds the target array length), the method throws an error.
- If provided a [typed array][@stdlib/array/typed] which shares an [`ArrayBuffer`][@stdlib/array/buffer] with the target array, the method will intelligently copy the source range to the destination range.

<a name="method-some"></a>

#### BooleanArray.prototype.some( predicate\[, thisArg] )

Returns a boolean indicating whether at least one element passes a test.

```javascript
function predicate( v ) {
return v === true;
}

var arr = new BooleanArray( 3 );

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

var bool = arr.some( predicate );
// returns true
```

The `predicate` function is provided three arguments:

- **value**: current array element.
- **index**: current array element index.
- **arr**: the array on which this method was called.

To set the function execution context, provide a `thisArg`.

```javascript
function predicate( v ) {
this.count += 1;
return v === true;
}

var arr = new BooleanArray( 3 );

var context = {
'count': 0
};

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

var bool = arr.some( predicate, context );
// returns true

var count = context.count;
// returns 2
```

<a name="method-sort"></a>

#### BooleanArray.prototype.sort( \[compareFcn] )
Expand Down
55 changes: 55 additions & 0 deletions bool/benchmark/benchmark.every.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// MAIN //

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

arr = new BooleanArray( [ true, false, false, true ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = arr.every( predicate );
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();

function predicate( v ) {
return v === true;
}
});
116 changes: 116 additions & 0 deletions bool/benchmark/benchmark.every.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/**
* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pow = require( '@stdlib/math/base/special/pow' );
var Boolean = require( '@stdlib/boolean/ctor' );
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// FUNCTIONS //

/**
* Predicate function.
*
* @private
* @param {boolean} value - array element
* @param {NonNegativeInteger} idx - array element index
* @param {BooleanArray} arr - array instance
* @returns {boolean} boolean indicating whether a value passes a test
*/
function predicate( value ) {
return value === true;
}

/**
* 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; i++ ) {
arr.push( Boolean( 1 ) );
}
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.every( predicate );
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+':every:len='+len, f );
}
}

main();
55 changes: 55 additions & 0 deletions bool/benchmark/benchmark.some.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
var pkg = require( './../package.json' ).name;
var BooleanArray = require( './../lib' );


// MAIN //

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

arr = new BooleanArray( [ true, false, false, true ] );

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
bool = arr.some( predicate );
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();

function predicate( v ) {
return v === true;
}
});
Loading

0 comments on commit 88b80eb

Please sign in to comment.