Skip to content

Commit 88e8013

Browse files
committed
Auto-generated commit
1 parent b9c5504 commit 88e8013

File tree

10 files changed

+479
-7
lines changed

10 files changed

+479
-7
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-09-25)
7+
## Unreleased (2024-11-18)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`956a462`](https://github.com/stdlib-js/stdlib/commit/956a4624c788689b1bca285856b987ea3aa32eb6) - add `forEach` method
1314
- [`a3a04e3`](https://github.com/stdlib-js/stdlib/commit/a3a04e32057b878529b86180e38ed3ae383c34ef) - add `array/fixed-endian-factory`
1415

1516
</section>
@@ -22,6 +23,7 @@
2223

2324
<details>
2425

26+
- [`956a462`](https://github.com/stdlib-js/stdlib/commit/956a4624c788689b1bca285856b987ea3aa32eb6) - **feat:** add `forEach` method _(by Athan Reines)_
2527
- [`b9f3b77`](https://github.com/stdlib-js/stdlib/commit/b9f3b776e5f3d426629b77206b682836fe6b390f) - **refactor:** reduce string literals _(by Athan Reines)_
2628
- [`17fa3d2`](https://github.com/stdlib-js/stdlib/commit/17fa3d277b28d85634444424f2af75edf60ab030) - **docs:** fix example _(by Athan Reines)_
2729
- [`a3a04e3`](https://github.com/stdlib-js/stdlib/commit/a3a04e32057b878529b86180e38ed3ae383c34ef) - **feat:** add `array/fixed-endian-factory` _(by Athan Reines)_

CONTRIBUTORS

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
#
33
# Contributors listed in alphabetical order.
44

5-
Aayush Khanna <96649223+aayush0325@users.noreply.github.com>
5+
Aayush Khanna <aayushiitbhu23@gmail.com>
6+
AbhijitRaut04 <121740684+AbhijitRaut04@users.noreply.github.com>
67
Adarsh Palaskar <adarshpalaskar99@gmail.com>
78
Aditya Sapra <adityaework@gmail.com>
89
AgPriyanshu18 <113460573+AgPriyanshu18@users.noreply.github.com>
@@ -21,13 +22,15 @@ Christopher Dambamuromo <chridam@gmail.com>
2122
Dan Rose <danoftheroses@gmail.com>
2223
Daniel Killenberger <daniel.killenberger@gmail.com>
2324
Daniel Yu <40680511+Daniel777y@users.noreply.github.com>
24-
DebashisMaharana <145602692+DevMhrn@users.noreply.github.com>
25+
Debashis Maharana <debashismaharana7854@gmail.com>
26+
Dominic Lim <46486515+domlimm@users.noreply.github.com>
2527
Dominik Moritz <domoritz@gmail.com>
2628
Dorrin Sotoudeh <dorrinsotoudeh123@gmail.com>
2729
EuniceSim142 <77243938+EuniceSim142@users.noreply.github.com>
2830
Frank Kovacs <fran70kk@gmail.com>
2931
Golden Kumar <103646877+AuenKr@users.noreply.github.com>
3032
Gunj Joshi <gunjjoshi8372@gmail.com>
33+
Gururaj Gurram <143020143+gururaj1512@users.noreply.github.com>
3134
HarshaNP <96897754+GittyHarsha@users.noreply.github.com>
3235
Harshita Kalani <harshitakalani02@gmail.com>
3336
Hridyanshu <124202756+HRIDYANSHU054@users.noreply.github.com>
@@ -44,6 +47,7 @@ Justin Dennison <justin1dennison@gmail.com>
4447
Kaif Mohd <mdkaifprofession@gmail.com>
4548
Karthik Prakash <116057817+skoriop@users.noreply.github.com>
4649
Khaldon <kahmd1444@gmail.com>
50+
Kohantika Nath <145763549+kohantikanath@users.noreply.github.com>
4751
Krishnendu Das <86651039+itskdhere@users.noreply.github.com>
4852
Lovelin <100030865+lovelindhoni@users.noreply.github.com>
4953
Manik Sharma <maniksharma.rke@gmail.com>
@@ -55,6 +59,7 @@ Mohammad Kaif <98884589+Kaif987@users.noreply.github.com>
5559
Momtchil Momtchev <momtchil@momtchev.com>
5660
Muhammad Haris <harriskhan047@outlook.com>
5761
Naresh Jagadeesan <naresh.naresh000@gmail.com>
62+
Neeraj Pathak <neerajrpathak710@gmail.com>
5863
NightKnight <Ahmedatwa866@yahoo.com>
5964
Nithin Katta <88046362+nithinkatta@users.noreply.github.com>
6065
Nourhan Hasan <109472010+TheNourhan@users.noreply.github.com>
@@ -65,15 +70,18 @@ Prajwal Kulkarni <prajwalkulkarni76@gmail.com>
6570
Pranav Goswami <goswami.4@iitj.ac.in>
6671
Praneki <97080887+PraneGIT@users.noreply.github.com>
6772
Pratik <97464067+Pratik772846@users.noreply.github.com>
73+
Pratyush Kumar Chouhan <pratyushkumar0308@gmail.com>
6874
Priyansh <88396544+itsspriyansh@users.noreply.github.com>
6975
Pushpendra Chandravanshi <pushpendrachandravanshi4@gmail.com>
76+
RISHAV <115060907+rishav2404@users.noreply.github.com>
7077
Raunak Kumar Gupta <raunakmodanwal321@gmail.com>
7178
Rejoan Sardar <119718513+Rejoan-Sardar@users.noreply.github.com>
7279
Ricky Reusser <rsreusser@gmail.com>
7380
Ridam Garg <67867319+RidamGarg@users.noreply.github.com>
7481
Robert Gislason <gztown2216@yahoo.com>
7582
Roman Stetsyk <25715951+romanstetsyk@users.noreply.github.com>
7683
Rutam <138517416+performant23@users.noreply.github.com>
84+
Ruthwik Chikoti <145591715+ruthwikchikoti@users.noreply.github.com>
7785
Ryan Seal <splrk@users.noreply.github.com>
7886
Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com>
7987
SarthakPaandey <145528240+SarthakPaandey@users.noreply.github.com>
@@ -94,6 +102,7 @@ Tudor Pagu <104032457+tudor-pagu@users.noreply.github.com>
94102
Tufailahmed Bargir <142114244+Tufailahmed-Bargir@users.noreply.github.com>
95103
Utkarsh <http://utkarsh11105@gmail.com>
96104
Utkarsh Raj <rajutkarsh2505@gmail.com>
105+
UtkershBasnet <119008923+UtkershBasnet@users.noreply.github.com>
97106
Vaibhav Patel <98279986+noobCoderVP@users.noreply.github.com>
98107
Varad Gupta <varadgupta21@gmail.com>
99108
Xiaochuan Ye <tap91624@gmail.com>

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,65 @@ var v = arr.get( 0 );
339339
// returns 1.0
340340
```
341341

342+
<a name="method-for-each"></a>
343+
344+
#### TypedArrayFE.prototype.forEach( callbackFn\[, thisArg] )
345+
346+
Invokes a function once for each array element.
347+
348+
```javascript
349+
function log( v, i ) {
350+
console.log( '%s: %s', i.toString(), v.toString() );
351+
}
352+
353+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
354+
355+
var arr = new Float64ArrayFE( 'little-endian', 3 );
356+
357+
arr.set( 1.5, 0 );
358+
arr.set( 2.5, 1 );
359+
arr.set( 3.5, 2 );
360+
361+
arr.forEach( log );
362+
/* =>
363+
0: 1.5
364+
1: 2.5
365+
2: 3.5
366+
*/
367+
```
368+
369+
The invoked function is provided three arguments:
370+
371+
- **value**: current array element.
372+
- **index**: current array element index.
373+
- **arr**: the array on which this method was called.
374+
375+
To set the function execution context, provide a `thisArg`.
376+
377+
```javascript
378+
function fcn( v, i ) {
379+
this.count += 1;
380+
console.log( '%s: %s', i.toString(), v.toString() );
381+
}
382+
383+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
384+
385+
var arr = new Float64ArrayFE( 'little-endian', 3 );
386+
387+
var context = {
388+
'count': 0
389+
};
390+
391+
arr.set( 1.0, 0 );
392+
arr.set( 2.0, 1 );
393+
arr.set( 3.0, 2 );
394+
395+
arr.forEach( fcn, context );
396+
397+
var count = context.count;
398+
// returns 3
399+
```
400+
342401
<a name="method-get"></a>
343402

344403
#### TypedArrayFE.prototype.get( i )

benchmark/benchmark.for_each.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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 isnan = require( '@stdlib/math-base-assert-is-nan' );
25+
var pkg = require( './../package.json' ).name;
26+
var factory = require( './../lib' );
27+
28+
29+
// VARIABLES //
30+
31+
var Float64ArrayFE = factory( 'float64' );
32+
33+
34+
// MAIN //
35+
36+
bench( pkg+':forEach', function benchmark( b ) {
37+
var arr;
38+
var i;
39+
40+
arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 2.0, 1.0 ] );
41+
42+
b.tic();
43+
for ( i = 0; i < b.iterations; i++ ) {
44+
arr.forEach( check );
45+
if ( arr.length !== 4 ) {
46+
b.fail( 'should not change an array length' );
47+
}
48+
}
49+
b.toc();
50+
if ( arr.length !== 4 ) {
51+
b.fail( 'should not change an array length' );
52+
}
53+
b.pass( 'benchmark finished' );
54+
b.end();
55+
56+
function check( v ) {
57+
if ( isnan( v ) ) {
58+
b.fail( 'should not return NaN' );
59+
}
60+
}
61+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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 zeroTo = require( '@stdlib/array-zero-to' );
26+
var isnan = require( '@stdlib/math-base-assert-is-nan' );
27+
var pkg = require( './../package.json' ).name;
28+
var factory = require( './../lib' );
29+
30+
31+
// VARIABLES //
32+
33+
var Float64ArrayFE = factory( 'float64' );
34+
35+
36+
// FUNCTIONS //
37+
38+
/**
39+
* Creates a benchmark function.
40+
*
41+
* @private
42+
* @param {PositiveInteger} len - array length
43+
* @returns {Function} benchmark function
44+
*/
45+
function createBenchmark( len ) {
46+
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
47+
return benchmark;
48+
49+
/**
50+
* Benchmark function.
51+
*
52+
* @private
53+
* @param {Benchmark} b - benchmark instance
54+
*/
55+
function benchmark( b ) {
56+
var i;
57+
58+
b.tic();
59+
for ( i = 0; i < b.iterations; i++ ) {
60+
arr.forEach( callback );
61+
if ( arr.length !== len ) {
62+
b.fail( 'should not change an array length' );
63+
}
64+
}
65+
b.toc();
66+
if ( arr.length !== len ) {
67+
b.fail( 'should not change an array length' );
68+
}
69+
b.pass( 'benchmark finished' );
70+
b.end();
71+
72+
function callback( value ) {
73+
if ( isnan( value ) ) {
74+
throw new Error( 'something went wrong' );
75+
}
76+
}
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var len;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
len = pow( 10, i );
100+
f = createBenchmark( len );
101+
bench( pkg+':forEach:len='+len, f );
102+
}
103+
}
104+
105+
main();

0 commit comments

Comments
 (0)