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 14, 2024
1 parent 1911b61 commit 616e0e8
Show file tree
Hide file tree
Showing 10 changed files with 979 additions and 1 deletion.
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-13)
## Unreleased (2024-06-14)

<section class="packages">

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

##### Features

- [`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)
- [`d71d044`](https://github.com/stdlib-js/stdlib/commit/d71d04433120ab3096fb01c546d96c60c7684681) - add `sort` method to `array/bool` [(#2363)](https://github.com/stdlib-js/stdlib/pull/2363)
- [`40da309`](https://github.com/stdlib-js/stdlib/commit/40da3097c6ffaed4cd9284d6cdeff8bf11786553) - add `map` method to `array/bool` [(#2292)](https://github.com/stdlib-js/stdlib/pull/2292)
- [`5d53c2d`](https://github.com/stdlib-js/stdlib/commit/5d53c2de22e6899dc3970b4714c0c4e228562f92) - add initial TypeScript declarations
Expand Down Expand Up @@ -1751,6 +1752,7 @@ A total of 13 people contributed to this release. Thank you to the following con

<details>

- [`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)_
- [`c417923`](https://github.com/stdlib-js/stdlib/commit/c4179233cb2de5ffaa8c59b3910e14de12414483) - **feat:** add boolean dtype support in `array/dtypes` [(#2307)](https://github.com/stdlib-js/stdlib/pull/2307) _(by Jaysukh Makvana, Athan Reines)_
- [`2a174cd`](https://github.com/stdlib-js/stdlib/commit/2a174cd91a26e08e7032934762ef2c0ed0320bda) - **feat:** add boolean dtype support in `array/promotion-rules` [(#2369)](https://github.com/stdlib-js/stdlib/pull/2369) _(by Jaysukh Makvana, Athan Reines)_
- [`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)_
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,110 @@ var len = arr.length;
// returns 4
```

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

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

Returns the first element in an array for which a predicate function returns a truthy value.

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

var arr = new BooleanArray( 3 );

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

var v = arr.find( 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, i ) {
this.count += 1;
return ( v === true );
}

var arr = new BooleanArray( 3 );

var context = {
'count': 0
};

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

var z = arr.find( predicate, context );
// returns true

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

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

#### Complex64Array.prototype.findLast( predicate\[, thisArg] )

Returns the last element in an array for which a predicate function returns a truthy value.

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

var arr = new BooleanArray( 3 );

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

var v = arr.findLast( 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, i ) {
this.count += 1;
return ( v === true );
}

var arr = new BooleanArray( 3 );

var context = {
'count': 0
};

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

var z = arr.findLast( predicate, context );
// returns true

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

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

#### BooleanArray.prototype.get( i )
Expand Down
55 changes: 55 additions & 0 deletions bool/benchmark/benchmark.find.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+':find', function benchmark( b ) {
var arr;
var v;
var i;

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

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

function predicate( v ) {
return ( v === false );
}
});
117 changes: 117 additions & 0 deletions bool/benchmark/benchmark.find.length.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/**
* @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 Boolean = require( '@stdlib/boolean/ctor' );
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
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 === false );
}

/**
* 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( Boolean( 1 ) );
}
arr.push( Boolean( 0 ) );
arr = new BooleanArray( arr );

return benchmark;

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

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
v = arr.find( predicate );
if ( typeof v !== 'boolean' ) {
b.fail( 'should return a boolean' );
}
}
b.toc();
if ( !isBoolean( v ) ) {
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+':find:len='+len, f );
}
}

main();
55 changes: 55 additions & 0 deletions bool/benchmark/benchmark.find_last.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+':findLast', function benchmark( b ) {
var arr;
var v;
var i;

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

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

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

0 comments on commit 616e0e8

Please sign in to comment.