Skip to content

Commit a6d4f67

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

16 files changed

+1605
-6
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-15)
7+
## Unreleased (2024-07-19)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`cb20ecc`](https://github.com/stdlib-js/stdlib/commit/cb20ecc5555cabbdfa9ad4807e096f8768f9f780) - add `copyWithin`, `entries`, `forEach` to `array/bool` [(#2611)](https://github.com/stdlib-js/stdlib/pull/2611)
1314
- [`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)
1415
- [`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)
1516
- [`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)
@@ -30,6 +31,7 @@
3031

3132
<details>
3233

34+
- [`cb20ecc`](https://github.com/stdlib-js/stdlib/commit/cb20ecc5555cabbdfa9ad4807e096f8768f9f780) - **feat:** add `copyWithin`, `entries`, `forEach` to `array/bool` [(#2611)](https://github.com/stdlib-js/stdlib/pull/2611) _(by Jaysukh Makvana, Athan Reines)_
3335
- [`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)_
3436
- [`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)_
3537
- [`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)_

README.md

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,121 @@ v = arr.at( -100 );
399399
// returns undefined
400400
```
401401

402+
<a name="method-copy-within"></a>
403+
404+
#### BooleanArray.prototype.copyWithin( target, start\[, end] )
405+
406+
Copies a sequence of elements within the array starting at `start` and ending at `end` (non-inclusive) to the position starting at `target`.
407+
408+
```javascript
409+
var arr = new BooleanArray( 4 );
410+
411+
arr.set( true, 0 );
412+
arr.set( false, 1 );
413+
arr.set( false, 2 );
414+
arr.set( true, 3 );
415+
416+
var v = arr.get( 0 );
417+
// returns true
418+
419+
v = arr.get( 1 );
420+
// returns false
421+
422+
// Copy the last two elements to the first two elements:
423+
arr.copyWithin( 0, 2 );
424+
425+
v = arr.get( 0 );
426+
// returns false
427+
428+
v = arr.get( 1 );
429+
// returns true
430+
```
431+
432+
By default, `end` equals the number of array elements (i.e., one more than the last array index). To limit the sequence length, provide an `end` argument.
433+
434+
```javascript
435+
var arr = new BooleanArray( 4 );
436+
437+
arr.set( true, 0 );
438+
arr.set( false, 1 );
439+
arr.set( false, 2 );
440+
arr.set( true, 3 );
441+
442+
var v = arr.get( 2 );
443+
// returns false
444+
445+
v = arr.get( 3 );
446+
// returns true
447+
448+
// Copy the first two elements to the last two elements:
449+
arr.copyWithin( 2, 0, 2 );
450+
451+
v = arr.get( 2 );
452+
// returns true
453+
454+
v = arr.get( 3 );
455+
// returns false
456+
```
457+
458+
When a `target`, `start`, and/or `end` index is negative, the respective index is determined relative to the last array element. The following example achieves the same behavior as the previous example:
459+
460+
```javascript
461+
var arr = new BooleanArray( 4 );
462+
463+
arr.set( true, 0 );
464+
arr.set( false, 1 );
465+
arr.set( false, 2 );
466+
arr.set( true, 3 );
467+
468+
var v = arr.get( 2 );
469+
// returns false
470+
471+
v = arr.get( 3 );
472+
// returns true
473+
474+
// Copy the first two elements to the last two elements using negative indices:
475+
arr.copyWithin( -2, -4, -2 );
476+
477+
v = arr.get( 2 );
478+
// returns true
479+
480+
v = arr.get( 3 );
481+
// returns false
482+
```
483+
484+
<a name="method-entries"></a>
485+
486+
#### BooleanArray.prototype.entries()
487+
488+
Returns an iterator for iterating over array key-value pairs.
489+
490+
```javascript
491+
var arr = new BooleanArray( 3 );
492+
493+
arr.set( true, 0 );
494+
arr.set( false, 1 );
495+
arr.set( true, 2 );
496+
497+
var it = arr.entries();
498+
499+
var v = it.next().value;
500+
// returns [ 0, true ]
501+
502+
v = it.next().value;
503+
// returns [ 1, false ]
504+
505+
v = it.next().value;
506+
// returns [ 2, true ]
507+
508+
var bool = it.next().done;
509+
// returns true
510+
```
511+
512+
The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the following properties:
513+
514+
- **next**: function which returns an [iterator][mdn-iterator-protocol] protocol-compliant object containing the next iterated value (if one exists) assigned to a `value` property and a `done` property having a `boolean` value indicating whether the [iterator][mdn-iterator-protocol] is finished.
515+
- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object.
516+
402517
<a name="method-every"></a>
403518

404519
#### BooleanArray.prototype.every( predicate\[, thisArg] )
@@ -779,6 +894,66 @@ var count = context.count;
779894
// returns 3
780895
```
781896

897+
<a name="method-for-each"></a>
898+
899+
#### BooleanArray.prototype.forEach( callbackFn\[, thisArg] )
900+
901+
Invokes a function once for each array element.
902+
903+
```javascript
904+
function log( v, i ) {
905+
console.log( '%s: %s', i, v.toString() );
906+
}
907+
908+
var arr = new BooleanArray( 3 );
909+
910+
arr.set( true, 0 );
911+
arr.set( false, 1 );
912+
arr.set( true, 2 );
913+
914+
arr.forEach( log );
915+
/* =>
916+
0: true
917+
1: false
918+
2: true
919+
*/
920+
```
921+
922+
The invoked function is provided three arguments:
923+
924+
- **value**: current array element.
925+
- **index**: current array element index.
926+
- **arr**: the array on which this method was called.
927+
928+
To set the function execution context, provide a `thisArg`.
929+
930+
```javascript
931+
function fcn( v, i ) {
932+
this.count += 1;
933+
console.log( '%s: %s', i, v.toString() );
934+
}
935+
936+
var arr = new BooleanArray( 3 );
937+
938+
var context = {
939+
'count': 0
940+
};
941+
942+
arr.set( true, 0 );
943+
arr.set( false, 1 );
944+
arr.set( true, 2 );
945+
946+
arr.forEach( fcn, context );
947+
/* =>
948+
0: 1 + 1i
949+
1: 2 + 2i
950+
2: 3 + 3i
951+
*/
952+
953+
var count = context.count;
954+
// returns 3
955+
```
956+
782957
<a name="method-get"></a>
783958

784959
#### BooleanArray.prototype.get( i )

benchmark/benchmark.copy_within.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 pkg = require( './../package.json' ).name;
25+
var BooleanArray = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+':copyWithin', function benchmark( b ) {
31+
var arr;
32+
var buf;
33+
var i;
34+
35+
arr = [];
36+
for ( i = 0; i < 5; i++ ) {
37+
arr.push( i%2 );
38+
}
39+
arr = new BooleanArray( arr );
40+
buf = arr.buffer;
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
buf[ 0 ] = i%2;
45+
arr = arr.copyWithin( 1, 0 );
46+
if ( buf[ 0 ] !== i%2 ) {
47+
b.fail( 'unexpected result' );
48+
}
49+
}
50+
b.toc();
51+
if ( buf[ 0 ] !== buf[ 0 ] ) {
52+
b.fail( 'should not be NaN' );
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 pkg = require( './../package.json' ).name;
26+
var BooleanArray = require( './../lib' );
27+
28+
29+
// FUNCTIONS //
30+
31+
/**
32+
* Creates a benchmark function.
33+
*
34+
* @private
35+
* @param {PositiveInteger} len - array length
36+
* @returns {Function} benchmark function
37+
*/
38+
function createBenchmark( len ) {
39+
var arr;
40+
var buf;
41+
var i;
42+
43+
arr = [];
44+
for ( i = 0; i < len+1; i++ ) {
45+
arr.push( i%2 );
46+
}
47+
arr = new BooleanArray( arr );
48+
buf = arr.buffer;
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 i;
60+
61+
b.tic();
62+
for ( i = 0; i < b.iterations; i++ ) {
63+
buf[ 0 ] = i%2;
64+
arr.copyWithin( 1, 0 );
65+
if ( buf[ 0 ] !== i%2 ) {
66+
b.fail( 'unexpected result' );
67+
}
68+
}
69+
b.toc();
70+
if ( buf[ 0 ] !== buf[ 0 ] ) {
71+
b.fail( 'should not be NaN' );
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+':copyWithin:len='+len, f );
100+
}
101+
}
102+
103+
main();

0 commit comments

Comments
 (0)