Skip to content

Commit f847675

Browse files
committed
Auto-generated commit
1 parent 1c8df49 commit f847675

File tree

10 files changed

+527
-5
lines changed

10 files changed

+527
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`40da309`](https://github.com/stdlib-js/stdlib/commit/40da3097c6ffaed4cd9284d6cdeff8bf11786553) - add `map` method to `array/bool` [(#2292)](https://github.com/stdlib-js/stdlib/pull/2292)
1314
- [`5d53c2d`](https://github.com/stdlib-js/stdlib/commit/5d53c2de22e6899dc3970b4714c0c4e228562f92) - add initial TypeScript declarations
1415
- [`e221398`](https://github.com/stdlib-js/stdlib/commit/e2213984af7a95af1b439aae8e2122968892c55d) - add `array/bool`
1516

@@ -23,6 +24,7 @@
2324

2425
<details>
2526

27+
- [`40da309`](https://github.com/stdlib-js/stdlib/commit/40da3097c6ffaed4cd9284d6cdeff8bf11786553) - **feat:** add `map` method to `array/bool` [(#2292)](https://github.com/stdlib-js/stdlib/pull/2292) _(by Jaysukh Makvana, Athan Reines)_
2628
- [`5d53c2d`](https://github.com/stdlib-js/stdlib/commit/5d53c2de22e6899dc3970b4714c0c4e228562f92) - **feat:** add initial TypeScript declarations _(by Athan Reines)_
2729
- [`133dd8b`](https://github.com/stdlib-js/stdlib/commit/133dd8bdce3709d5aeda84906b79882f86d9989d) - **chore:** update package meta data [(##2251)](#2251) _(by stdlib-bot)_
2830
- [`be3061e`](https://github.com/stdlib-js/stdlib/commit/be3061ee5500fd70d7c39fa7e6299164e57c8b98) - **docs:** fix example _(by Athan Reines)_
@@ -38,9 +40,10 @@
3840

3941
### Contributors
4042

41-
A total of 1 person contributed to this release. Thank you to this contributor:
43+
A total of 2 people contributed to this release. Thank you to the following contributors:
4244

4345
- Athan Reines
46+
- Jaysukh Makvana
4447

4548
</section>
4649

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,67 @@ var v = arr.get( 100 );
393393
// returns undefined
394394
```
395395

396+
<a name="method-map"></a>
397+
398+
#### BooleanArray.prototype.map( callbackFn\[, thisArg] )
399+
400+
Returns a new array with each element being the result of a provided callback function.
401+
402+
```javascript
403+
function invert( v ) {
404+
return !v;
405+
}
406+
407+
var arr = new BooleanArray( 3 );
408+
409+
arr.set( true, 0 );
410+
arr.set( false, 1 );
411+
arr.set( true, 2 );
412+
413+
var out = arr.map( invert );
414+
// returns <BooleanArray>
415+
416+
var z = out.get( 0 );
417+
// returns false
418+
419+
z = out.get( 1 );
420+
// returns true
421+
422+
z = out.get( 2 );
423+
// returns false
424+
```
425+
426+
The callback function is provided three arguments:
427+
428+
- **value**: current array element.
429+
- **index**: current array element index.
430+
- **arr**: the array on which this method was called.
431+
432+
To set the function execution context, provide a `thisArg`.
433+
434+
```javascript
435+
function invert( v, i ) {
436+
this.count += i;
437+
return !v;
438+
}
439+
440+
var arr = new BooleanArray( 3 );
441+
442+
var context = {
443+
'count': 0
444+
};
445+
446+
arr.set( true, 0 );
447+
arr.set( false, 1 );
448+
arr.set( true, 2 );
449+
450+
var out = arr.map( invert, context );
451+
// returns <BooleanArray>
452+
453+
var count = context.count;
454+
// returns 3;
455+
```
456+
396457
<a name="method-set"></a>
397458

398459
#### BooleanArray.prototype.set( v\[, i] )

benchmark/benchmark.map.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+':map', function benchmark( b ) {
32+
var out;
33+
var arr;
34+
var i;
35+
36+
arr = new BooleanArray( [ true, false, false, true, true, false ] );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
out = arr.map( invert );
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+
52+
function invert( v ) {
53+
return !v;
54+
}
55+
});

benchmark/benchmark.map.length.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 Boolean = require( '@stdlib/boolean-ctor' );
26+
var identity = require( '@stdlib/utils-identity-function' );
27+
var isBooleanArray = require( '@stdlib/assert-is-booleanarray' );
28+
var pkg = require( './../package.json' ).name;
29+
var BooleanArray = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var arr;
43+
var i;
44+
45+
arr = [];
46+
for ( i = 0; i < len; i++ ) {
47+
arr.push( Boolean( i%2 ) );
48+
}
49+
arr = new BooleanArray( arr );
50+
51+
return benchmark;
52+
53+
/**
54+
* Benchmark function.
55+
*
56+
* @private
57+
* @param {Benchmark} b - benchmark instance
58+
*/
59+
function benchmark( b ) {
60+
var out;
61+
var i;
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
out = arr.map( identity );
66+
if ( typeof out !== 'object' ) {
67+
b.fail( 'should return an object' );
68+
}
69+
}
70+
b.toc();
71+
if ( !isBooleanArray( out ) ) {
72+
b.fail( 'should return a BooleanArray' );
73+
}
74+
b.pass( 'benchmark finished' );
75+
b.end();
76+
}
77+
}
78+
79+
80+
// MAIN //
81+
82+
/**
83+
* Main execution sequence.
84+
*
85+
* @private
86+
*/
87+
function main() {
88+
var len;
89+
var min;
90+
var max;
91+
var f;
92+
var i;
93+
94+
min = 1; // 10^min
95+
max = 6; // 10^max
96+
97+
for ( i = min; i <= max; i++ ) {
98+
len = pow( 10, i );
99+
f = createBenchmark( len );
100+
bench( pkg+':map:len='+len, f );
101+
}
102+
}
103+
104+
main();

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)