Skip to content

Commit 1233f60

Browse files
committed
Auto-generated commit
1 parent 4aa1ce2 commit 1233f60

13 files changed

+1360
-5
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-06-23)
7+
## Unreleased (2024-06-29)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`29615af`](https://github.com/stdlib-js/stdlib/commit/29615af970796a43f65f4b00d29bd23a122f2208) - add `slice` and `subarray` methods to `array/bool` [(#2472)](https://github.com/stdlib-js/stdlib/pull/2472)
1314
- [`fbc42b4`](https://github.com/stdlib-js/stdlib/commit/fbc42b4c66cf695c6c114f64bf3eff65186026f0) - add `includes` method to `array/bool` [(#2441)](https://github.com/stdlib-js/stdlib/pull/2441)
1415
- [`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)
1516
- [`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)
@@ -25,6 +26,7 @@
2526

2627
<details>
2728

29+
- [`29615af`](https://github.com/stdlib-js/stdlib/commit/29615af970796a43f65f4b00d29bd23a122f2208) - **feat:** add `slice` and `subarray` methods to `array/bool` [(#2472)](https://github.com/stdlib-js/stdlib/pull/2472) _(by Jaysukh Makvana, Athan Reines)_
2830
- [`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)_
2931
- [`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)_
3032
- [`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)_

README.md

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,82 @@ A few notes:
898898
- 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.
899899
- 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.
900900

901+
<a name="method-slice"></a>
902+
903+
#### BooleanArray.prototype.slice( \[start\[, end]] )
904+
905+
Copies a portion of a typed array to a new typed array.
906+
907+
```javascript
908+
var arr = new BooleanArray( 5 );
909+
910+
arr.set( true, 0 );
911+
arr.set( false, 1 );
912+
arr.set( true, 2 );
913+
arr.set( false, 3 );
914+
arr.set( true, 4 );
915+
916+
var out = arr.slice();
917+
// returns <BooleanArray>
918+
919+
var len = out.length;
920+
// returns 5
921+
922+
var bool = out.get( 0 );
923+
// returns true
924+
925+
bool = out.get( len-1 );
926+
// returns true
927+
```
928+
929+
By default, the method returns a typed array beginning with the first array element. To specify an alternative array index at which to begin, provide a `start` index (inclusive).
930+
931+
```javascript
932+
var arr = new BooleanArray( 5 );
933+
934+
arr.set( true, 0 );
935+
arr.set( false, 1 );
936+
arr.set( true, 2 );
937+
arr.set( false, 3 );
938+
arr.set( true, 4 );
939+
940+
var out = arr.slice( 1 );
941+
// returns <BooleanArray>
942+
943+
var len = out.length;
944+
// returns 4
945+
946+
var bool = out.get( 0 );
947+
// returns false
948+
949+
bool = out.get( len-1 );
950+
// returns true
951+
```
952+
953+
By default, the method returns a typed array which includes all array elements after `start`. To limit the number of array elements after `start`, provide an `end` index (exclusive).
954+
955+
```javascript
956+
var arr = new BooleanArray( 5 );
957+
958+
arr.set( true, 0 );
959+
arr.set( false, 1 );
960+
arr.set( true, 2 );
961+
arr.set( false, 3 );
962+
arr.set( true, 4 );
963+
964+
var out = arr.slice( 1, -2 );
965+
// returns <BooleanArray>
966+
967+
var len = out.length;
968+
// returns 2
969+
970+
var bool = out.get( 0 );
971+
// returns false
972+
973+
bool = out.get( len-1 );
974+
// returns true
975+
```
976+
901977
<a name="method-some"></a>
902978

903979
#### BooleanArray.prototype.some( predicate\[, thisArg] )
@@ -1001,6 +1077,82 @@ The function should return a number where:
10011077

10021078
<a name="method-to-reversed"></a>
10031079

1080+
<a name="method-subarray"></a>
1081+
1082+
#### BooleanArray.prototype.subarray( \[begin\[, end]] )
1083+
1084+
Creates a new typed array view over the same underlying [`ArrayBuffer`][@stdlib/array/buffer] and with the same underlying data type as the host array.
1085+
1086+
```javascript
1087+
var arr = new BooleanArray( 5 );
1088+
1089+
arr.set( true, 0 );
1090+
arr.set( false, 1 );
1091+
arr.set( true, 2 );
1092+
arr.set( false, 3 );
1093+
arr.set( true, 4 );
1094+
1095+
var subarr = arr.subarray();
1096+
// returns <BooleanArray>
1097+
1098+
var len = subarr.length;
1099+
// returns 5
1100+
1101+
var bool = subarr.get( 0 );
1102+
// returns true
1103+
1104+
bool = subarr.get( len-1 );
1105+
// returns true
1106+
```
1107+
1108+
By default, the method creates a typed array view beginning with the first array element. To specify an alternative array index at which to begin, provide a `begin` index (inclusive).
1109+
1110+
```javascript
1111+
var arr = new BooleanArray( 5 );
1112+
1113+
arr.set( true, 0 );
1114+
arr.set( false, 1 );
1115+
arr.set( true, 2 );
1116+
arr.set( false, 3 );
1117+
arr.set( true, 4 );
1118+
1119+
var subarr = arr.subarray( 1 );
1120+
// returns <BooleanArray>
1121+
1122+
var len = subarr.length;
1123+
// returns 4
1124+
1125+
var bool = subarr.get( 0 );
1126+
// returns false
1127+
1128+
bool = subarr.get( len-1 );
1129+
// returns true
1130+
```
1131+
1132+
By default, the method creates a typed array view which includes all array elements after `begin`. To limit the number of array elements after `begin`, provide an `end` index (exclusive).
1133+
1134+
```javascript
1135+
var arr = new BooleanArray( 5 );
1136+
1137+
arr.set( true, 0 );
1138+
arr.set( false, 1 );
1139+
arr.set( true, 2 );
1140+
arr.set( false, 3 );
1141+
arr.set( true, 4 );
1142+
1143+
var subarr = arr.subarray( 1, -2 );
1144+
// returns <BooleanArray>
1145+
1146+
var len = subarr.length;
1147+
// returns 2
1148+
1149+
var bool = subarr.get( 0 );
1150+
// returns false
1151+
1152+
bool = subarr.get( len-1 );
1153+
// returns true
1154+
```
1155+
10041156
#### BooleanArray.prototype.toReversed()
10051157

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

benchmark/benchmark.slice.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+':slice', function benchmark( b ) {
32+
var out;
33+
var arr;
34+
var i;
35+
36+
arr = new BooleanArray( [ true, false, false, true ] );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
out = arr.slice();
41+
if ( typeof out !== 'object' ) {
42+
b.fail( 'should return an object' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBooleanArray( out ) ) {
47+
b.fail( 'should return a BooleanArray' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});

benchmark/benchmark.slice.length.js

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) 2023 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 Boolean = require( '@stdlib/boolean-ctor' );
26+
var pow = require( '@stdlib/math-base-special-pow' );
27+
var pkg = require( './../package.json' ).name;
28+
var BooleanArray = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var arr;
42+
var i;
43+
44+
arr = [];
45+
for ( i = 0; i < len; i++ ) {
46+
arr.push( Boolean( i%2 ) );
47+
}
48+
arr = new BooleanArray( arr );
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 out;
60+
var i;
61+
62+
b.tic();
63+
for ( i = 0; i < b.iterations; i++ ) {
64+
out = arr.slice();
65+
if ( typeof out !== 'object' ) {
66+
b.fail( 'should return an object' );
67+
}
68+
}
69+
b.toc();
70+
if ( !isBooleanArray( out ) ) {
71+
b.fail( 'should return a BooleanArray' );
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+':slice:len='+len, f );
100+
}
101+
}
102+
103+
main();

benchmark/benchmark.subarray.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+':subarray', function benchmark( b ) {
32+
var out;
33+
var arr;
34+
var i;
35+
36+
arr = new BooleanArray( [ true, false, false, true ] );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
out = arr.subarray();
41+
if ( typeof out !== 'object' ) {
42+
b.fail( 'should return an object' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBooleanArray( out ) ) {
47+
b.fail( 'should return a BooleanArray' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});

0 commit comments

Comments
 (0)