10000 Auto-generated commit · stdlib-js/array-bool@8f9e001 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f9e001

Browse files
committed
Auto-generated commit
1 parent c45ac80 commit 8f9e001

20 files changed

+2031
-9
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-07-13)
7+
## Unreleased (2024-07-15)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`7c17308`](https://github.com/stdlib-js/stdlib/commit/7c17308587cd0fbac9812f258e3cd774cbdfc8da) - add `at`, `fill`, `filter`, and `toLocalestring` methods to `array/bool` [(#2607)](https://github.com/stdlib-js/stdlib/pull/2607)
1314
- [`ce3ad9a`](https://github.com/stdlib-js/stdlib/commit/ce3ad9a98468829b294708ca188ec669056e58ed) - add `keys`, `values`, and `with` methods to `array/bool` [(#2590)](https://github.com/stdlib-js/stdlib/pull/2590)
1415
- [`5a66b4b`](https://github.com/stdlib-js/stdlib/commit/5a66b4bb677cdbc4706811ea9f776343297c9f87) - add `join` and `toString` methods to `array/bool` [(#2557)](https://github.com/stdlib-js/stdlib/pull/2557)
1516
- [`4a6be43`](https://github.com/stdlib-js/stdlib/commit/4a6be430830868fb181bfa0b8923f37dabaffe8a) - add `reduce` and `reduceRight` methods to `array/bool` [(#2509)](https://github.com/stdlib-js/stdlib/pull/2509)
@@ -29,6 +30,7 @@
2930

3031
<details>
3132

33+
- [`7c17308`](https://github.com/stdlib-js/stdlib/commit/7c17308587cd0fbac9812f258e3cd774cbdfc8da) - **feat:** add `at`, `fill`, `filter`, and `toLocalestring` methods to `array/bool` [(#2607)](https://github.com/stdlib-js/stdlib/pull/2607) _(by Jaysukh Makvana, Athan Reines)_
3234
- [`ce3ad9a`](https://github.com/stdlib-js/stdlib/commit/ce3ad9a98468829b294708ca188ec669056e58ed) - **feat:** add `keys`, `values`, and `with` methods to `array/bool` [(#2590)](https://github.com/stdlib-js/stdlib/pull/2590) _(by Jaysukh Makvana)_
3335
- [`5a66b4b`](https://github.com/stdlib-js/stdlib/commit/5a66b4bb677cdbc4706811ea9f776343297c9f87) - **feat:** add `join` and `toString` methods to `array/bool` [(#2557)](https://github.com/stdlib-js/stdlib/pull/2557) _(by Jaysukh Makvana, Athan Reines)_
3436
- [`a78f7d1`](https://github.com/stdlib-js/stdlib/commit/a78f7d1b859b6b1d7b0bc0ee4daf76789e3e0910) - **style:** add missing spaces _(by Philipp Burckhardt)_

README.md

Lines changed: 176 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,38 @@ var len = arr.length;
367367
// returns 4
368368
```
369369

370+
<a name="method-at"></a>
371+
372+
#### BooleanArray.prototype.at( i )
373+
374+
Returns an array element located at integer position (index) `i`, with support for both nonnegative and negative integer positions.
375+
376+
```javascript
377+
var arr = new BooleanArray( 3 );
378+
379+
arr.set( true, 0 );
380+
arr.set( false, 1 );
381+
arr.set( true, 2 );
382+
383+
var v = arr.at( 0 );
384+
// returns true
385+
386+
v = arr.at( -1 );
387+
// returns true
388+
```
389+
390+
If provided an out-of-bounds index, the method returns `undefined`.
391+
392+
```javascript
393+
var arr = new BooleanArray( 10 );
394+
395+
var v = arr.at( 100 );
396+
// returns undefined
397+
398+
v = arr.at( -100 );
399+
// returns undefined
400+
```
401+
370402
<a name="method-every"></a>
371403

372404
#### BooleanArray.prototype.every( predicate\[, thisArg] )
@@ -419,6 +451,126 @@ var count = context.count;
419451
// returns 3
420452
```
421453

454+
<a name="method-fill"></a>
455+
456+
#### BooleanArray.prototype.fill( value\[, start\[, end]] )
457+
458+
Returns a modified typed array filled with a fill value.
459+
460+
```javascript
461+
var arr = new BooleanArray( 3 );
462+
463+
// Set all elements to the same value:
464+
arr.fill( true );
465+
466+
var v = arr.get( 0 );
467+
// returns true
468+
469+
v = arr.get( 1 );
470+
// returns true
471+
472+
v = arr.get( 2 );
473+
// returns true
474+
475+
// Fill all elements starting from the second element:
476+
arr.fill( false, 1 );
477+
478+
v = arr.get( 1 );
479+
// returns false
480+
481+
v = arr.get( 2 );
482+
// returns false
483+
484+
// Fill all elements from first element until the second-to-last element:
485+
arr.fill( false, 0, 2 );
486+
487+
v = arr.get( 0 );
488+
// returns false
489+
490+
v = arr.get( 1 );
491+
// returns false
492+
```
493+
494+
When a `start` and/or `end` index is negative, the respective index is determined relative to the last array element.
495+
496+
```javascript
497+
var arr = new BooleanArray( 3 );
498+
499+
// Set all array elements, except the last element, to the same value:
500+
arr.fill( true, 0, -1 );
501+
502+
var v = arr.get( 0 );
503+
// returns true
504+
505+
v = arr.get( 2 );
506+
// returns false
507+
```
508+
509+
<a name="method-filter"></a>
510+
511+
#### BooleanArray.prototype.filter( predicate\[, thisArg] )
512+
513+
Returns a new array containing the elements of an array which pass a test implemented by a predicate function.
514+
515+
```javascript
516+
function predicate( v ) {
517+
return ( v === true );
518+
}
519+
520+
var arr = new BooleanArray( 3 );
< F987 code>521+
522+
// Set the first three elements:
523+
arr.set( true, 0 );
524+
arr.set( false, 1 );
525+
arr.set( true, 2 );
526+
527+
var out = arr.filter( predicate );
528+
// returns <BooleanArray>
529+
530+
var len = out.length;
531+
// returns 2
532+
533+
var v = out.get( 0 );
534+
// returns true
535+
536+
v = out.get( 1 );
537+
// return true
538+
```
539+
540+
The `predicate` function is provided three arguments:
541+
542+
- **value**: current array element.
543+
- **index**: current array element index.
544+
- **arr**: the array on which this method was called.
545+
546+
To set the function execution context, provide a `thisArg`.
547+
548+
```javascript
549+
function predicate( v, i ) {
550+
this.count += 1;
551+
return ( v === true );
552+
}
553+
554+
var arr = new BooleanArray( 3 );
555+
556+
var context = {
557+
'count': 0
558+
};
559+
560+
arr.set( true, 0 );
561+
arr.set( false, 1 );
562+
arr.set( true, 2 );
563+
564+
var out = arr.filter( predicate, context );
565+
// returns <BooleanArray>
566+
567+
var len = out.length;
568+
// returns 2
569+
570+
var count = context.count;
571+
// returns 3
572+
```
573+
422574
<a name="method-find"></a>
423575

424576
#### BooleanArray.prototype.find( predicate\[, thisArg] )
@@ -1230,8 +1382,6 @@ The function should return a number where:
12301382
- a positive value indicates that `a` should come after `b`.
12311383
- zero or `NaN` indicates that `a` and `b` are considered equal.
12321384

1233-
<a name="method-to-reversed"></a>
1234-
12351385
<a name="method-subarray"></a>
12361386

12371387
#### BooleanArray.prototype.subarray( \[begin\[, end]] )
@@ -1308,6 +1458,30 @@ bool = subarr.get( len-1 );
13081458
// returns true
13091459
```
13101460

1461+
<a name="method-to-locale-string"></a>
1462+
1463+
#### BooleanArray.prototype.toLocaleString( \[locales\[, options]] )
1464+
1465+
Serializes an array as a locale-specific string.
1466+
1467+
```javascript
1468+
var arr = new BooleanArray( 3 );
1469+
1470+
arr.set( true, 0 );
1471+
arr.set( false, 1 );
1472+
arr.set( true, 2 );
1473+
1474+
var str = arr.toLocaleString();
1475+
// returns 'true,false,true'
1476+
```
1477+
1478+
The method supports the following arguments:
1479+
1480+
- **locales**: a string with a BCP 47 language tag or an array of such strings.
1481+
- **options**: configuration properties.
1482+
1483+
<a name="method-to-reversed"></a>
1484+
13111485
#### BooleanArray.prototype.toReversed()
13121486

13131487
Returns a new typed array containing the elements in reversed order.

benchmark/benchmark.at.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var BooleanArray = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+'::nonnegative_indices:at', function benchmark( b ) {
32+
var arr;
33+
var N;
34+
var v;
35+
var i;
36+
37+
arr = [];
38+
for ( i = 0; i < 10; i++ ) {
39+
arr.push( true );
40+
}
41+
arr = new BooleanArray( arr );
42+
N = arr.length;
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
v = arr.at( i%N );
47+
if ( typeof v !== 'boolean' ) {
48+
b.fail( 'should return a boolean' );
49+
}
50+
}
51+
b.toc();
52+
if ( !isBoolean( v ) ) {
53+
b.fail( 'should return a boolean' );
54+
}
55+
b.pass( 'benchmark finished' );
56+
b.end();
57+
});
58+
59+
bench( pkg+'::negative_indices:at', function benchmark( b ) {
60+
var arr;
61+
var N;
62+
var v;
63+
var i;
64+
65+
arr = [];
66+
for ( i = 0; i < 10; i++ ) {
67+
arr.push( true );
68+
}
69+
arr = new BooleanArray( arr );
70+
N = arr.length;
71+
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
v = arr.at( -(i%N)-1 );
75+
if ( typeof v !== 'boolean' ) {
76+
b.fail( 'should return a boolean' );
77+
}
78+
}
79+
b.toc();
80+
if ( !isBoolean( v ) ) {
81+
b.fail( 'should return a boolean' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
});

benchmark/benchmark.every.length.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
var bench = require( '@stdlib/bench-harness' );
2424
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
2525
var pow = require( '@stdlib/math-base-special-pow' );
26-
var Boolean = require( '@stdlib/boolean-ctor' );
2726
var pkg = require( './../package.json' ).name;
2827
var BooleanArray = require( './../lib' );
2928

@@ -56,7 +55,7 @@ function createBenchmark( len ) {
5655

5756
arr = [];
5857
for ( i = 0; i < len; i++ ) {
59-
arr.push( Boolean( 1 ) );
58+
arr.push( true );
6059
}
6160
arr = new BooleanArray( arr );
6261

benchmark/benchmark.fill.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 isBooleanArray = require( '@stdlib/assert-is-booleanarray' );
25+
var pkg = require( './../package.json' ).name;
26+
var BooleanArray = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':fill', function benchmark( b ) {
32+
var values;
33+
var arr;
34+
var out;
35+
var i;
36+
37+
values = [
38+
true,
39+
false
40+
];
41+
arr = new BooleanArray( 5 );
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
out = arr.fill( values[ i%values.length ] );
46+
if ( typeof out !== 'object' ) {
47+
b.fail( 'should return an object' );
48+
}
49+
}
50+
b.toc();
51+
if ( !isBooleanArray( out ) ) {
52+
b.fail( 'should return a BooleanArray' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
});

0 commit comments

Comments
 (0)
0