Skip to content

Commit fc03caf

Browse files
committed
Auto-generated commit
1 parent b42e11d commit fc03caf

File tree

10 files changed

+454
-7
lines changed

10 files changed

+454
-7
lines changed

CHANGELOG.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
55
<section class="release" id="unreleased">
66

7-
## Unreleased (2024-11-20)
7+
## Unreleased (2024-11-22)
88

99
<section class="features">
1010

1111
### Features
1212

13+
- [`e3a2173`](https://github.com/stdlib-js/stdlib/commit/e3a2173a24bd8634f333cace626fc2d71740ebd3) - add `every` method to `array/fixed-endian-factory` [(#3200)](https://github.com/stdlib-js/stdlib/pull/3200)
1314
- [`b34732c`](https://github.com/stdlib-js/stdlib/commit/b34732cf655db60fbc798e12952f88c3edb07eaf) - add `at` method to `array/fixed-endian-factory` [(#3184)](https://github.com/stdlib-js/stdlib/pull/3184)
1415
- [`956a462`](https://github.com/stdlib-js/stdlib/commit/956a4624c788689b1bca285856b987ea3aa32eb6) - add `forEach` method
1516
- [`a3a04e3`](https://github.com/stdlib-js/stdlib/commit/a3a04e32057b878529b86180e38ed3ae383c34ef) - add `array/fixed-endian-factory`
@@ -22,9 +23,9 @@
2223

2324
### Closed Issues
2425

25-
This release closes the following issue:
26+
A total of 2 issues were closed in this release:
2627

27-
[#3135](https://github.com/stdlib-js/stdlib/issues/3135)
28+
[#3135](https://github.com/stdlib-js/stdlib/issues/3135), [#3138](https://github.com/stdlib-js/stdlib/issues/3138)
2829

2930
</section>
3031

@@ -36,6 +37,7 @@ This release closes the following issue:
3637

3738
<details>
3839

40+
- [`e3a2173`](https://github.com/stdlib-js/stdlib/commit/e3a2173a24bd8634f333cace626fc2d71740ebd3) - **feat:** add `every` method to `array/fixed-endian-factory` [(#3200)](https://github.com/stdlib-js/stdlib/pull/3200) _(by Aayush Khanna, Athan Reines)_
3941
- [`b34732c`](https://github.com/stdlib-js/stdlib/commit/b34732cf655db60fbc798e12952f88c3edb07eaf) - **feat:** add `at` method to `array/fixed-endian-factory` [(#3184)](https://github.com/stdlib-js/stdlib/pull/3184) _(by Aayush Khanna, Athan Reines)_
4042
- [`956a462`](https://github.com/stdlib-js/stdlib/commit/956a4624c788689b1bca285856b987ea3aa32eb6) - **feat:** add `forEach` method _(by Athan Reines)_
4143
- [`b9f3b77`](https://github.com/stdlib-js/stdlib/commit/b9f3b776e5f3d426629b77206b682836fe6b390f) - **refactor:** reduce string literals _(by Athan Reines)_

CONTRIBUTORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Ruthwik Chikoti <145591715+ruthwikchikoti@users.noreply.github.com>
8585
Ryan Seal <splrk@users.noreply.github.com>
8686
Sai Srikar Dumpeti <80447788+the-r3aper7@users.noreply.github.com>
8787
SarthakPaandey <145528240+SarthakPaandey@users.noreply.github.com>
88+
Saurabh Singh <saurabhsraghuvanshi@gmail.com>
8889
Seyyed Parsa Neshaei <spneshaei@users.noreply.github.com>
8990
Shashank Shekhar Singh <shashankshekharsingh1205@gmail.com>
9091
Shivam <11shivam00@gmail.com>

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,54 @@ v = arr.at( -100 );
371371
// returns undefined
372372
```
373373

374+
<a name="method-every"></a>
375+
376+
#### TypedArrayFE.prototype.every( predicate\[, thisArg] )
377+
378+
Tests whether all the elements in an array pass a test implemented by a predicate function.
379+
380+
```javascript
381+
function isNegative( v ) {
382+
return v < 0;
383+
}
384+
385+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
386+
387+
var arr = new Float64ArrayFE( 'little-endian', [ -1.0, -2.0, -3.0, -4.0 ] );
388+
389+
var bool = arr.every( isNegative );
390+
// returns true
391+
```
392+
393+
The invoked function is provided three arguments:
394+
395+
- **value**: current array element.
396+
- **index**: current array element index.
397+
- **arr**: the array on which this method was called.
398+
399+
To set the function execution context, provide a `thisArg`.
400+
401+
```javascript
402+
function isPositive( v, i ) {
403+
this.count += 1;
404+
return v > 0;
405+
}
406+
407+
var Float64ArrayFE = fixedEndianFactory( 'float64' );
408+
409+
var arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, -3.0 ] );
410+
411+
var context = {
412+
'count': 0
413+
};
414+
415+
var bool = arr.every( isPositive, context );
416+
// returns false
417+
418+
var count = context.count;
419+
// returns 3
420+
```
421+
374422
<a name="method-for-each"></a>
375423

376424
#### TypedArrayFE.prototype.forEach( callbackFn\[, thisArg] )

benchmark/benchmark.every.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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' );
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+':every', function benchmark( b ) {
37+
var bool;
38+
var arr;
39+
var i;
40+
41+
arr = new Float64ArrayFE( 'little-endian', [ 1.0, 2.0, 2.0, 1.0 ] );
42+
43+
b.tic();
44+
for ( i = 0; i < b.iterations; i++ ) {
45+
bool = arr.every( predicate );
46+
if ( typeof bool !== 'boolean' ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
}
50+
b.toc();
51+
if ( !isBoolean( bool ) ) {
52+
b.fail( 'should return a boolean' );
53+
}
54+
b.pass( 'benchmark finished' );
55+
b.end();
56+
57+
function predicate( v ) {
58+
return v > 0;
59+
}
60+
});
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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 isBoolean = require( '@stdlib/assert-is-boolean' );
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+
* Predicate function.
40+
*
41+
* @private
42+
* @param {boolean} value - array element
43+
* @param {NonNegativeInteger} idx - array element index
44+
* @param {TypedArray} arr - array instance
45+
* @returns {boolean} boolean indicating whether a value passes a test
46+
*/
47+
function predicate( value ) {
48+
return value >= 0;
49+
}
50+
51+
/**
52+
* Creates a benchmark function.
53+
*
54+
* @private
55+
* @param {PositiveInteger} len - array length
56+
* @returns {Function} benchmark function
57+
*/
58+
function createBenchmark( len ) {
59+
var arr = new Float64ArrayFE( 'little-endian', zeroTo( len ) );
60+
return benchmark;
61+
62+
/**
63+
* Benchmark function.
64+
*
65+
* @private
66+
* @param {Benchmark} b - benchmark instance
67+
*/
68+
function benchmark( b ) {
69+
var bool;
70+
var i;
71+
72+
b.tic();
73+
for ( i = 0; i < b.iterations; i++ ) {
74+
bool = arr.every( predicate );
75+
if ( typeof bool !== 'boolean' ) {
76+
b.fail( 'should return a boolean' );
77+
}
78+
}
79+
b.toc();
80+
if ( !isBoolean( bool ) ) {
81+
b.fail( 'should return a boolean' );
82+
}
83+
b.pass( 'benchmark finished' );
84+
b.end();
85+
}
86+
}
87+
88+
89+
// MAIN //
90+
91+
/**
92+
* Main execution sequence.
93+
*
94+
* @private
95+
*/
96+
function main() {
97+
var len;
98+
var min;
99+
var max;
100+
var f;
101+
var i;
102+
103+
min = 1; // 10^min
104+
max = 6; // 10^max
105+
106+
for ( i = min; i <= max; i++ ) {
107+
len = pow( 10, i );
108+
f = createBenchmark( len );
109+
bench( pkg+':every:len='+len, f );
110+
}
111+
}
112+
113+
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.

lib/main.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,37 @@ function factory( dtype ) { // eslint-disable-line max-lines-per-function, stdli
538538
*/
539539
setReadOnly( TypedArray.prototype, 'BYTES_PER_ELEMENT', TypedArray.BYTES_PER_ELEMENT );
540540

541+
/**
542+
* Tests whether all elements in an array pass a test implemented by a predicate function.
543+
*
544+
* @name every
545+
* @memberof TypedArray.prototype
546+
* @type {Function}
547+
* @param {Function} predicate - predicate function
548+
* @param {*} [thisArg] - function invocation context
549+
* @throws {TypeError} `this` must be a typed array instance
550+
* @throws {TypeError} first argument must be a function
551+
* @returns {boolean} boolean indicating whether all elements pass a test
552+
*/
553+
setReadOnly( TypedArray.prototype, 'every', function every( predicate, thisArg ) {
554+
var buf;
555+
var i;
556+
557+
if ( !isTypedArray( this ) ) {
558+
throw new TypeError( format( 'invalid invocation. `this` is not %s %s.', CHAR2ARTICLE[ dtype[0] ], CTOR_NAME ) );
559+
}
560+
if ( !isFunction( predicate ) ) {
561+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
562+
}
563+
buf = this._buffer;
564+
for ( i = 0; i < this._length; i++ ) {
565+
if ( !predicate.call( thisArg, buf[ GETTER ]( i * BYTES_PER_ELEMENT, this._isLE ), i, this ) ) {
566+
return false;
567+
}
568+
}
569+
return true;
570+
});
571+
541572
/**
542573
* Invokes a function once for each array element.
543574
*

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"@stdlib/array-float64": "^0.2.2",
6565
"@stdlib/array-zero-to": "^0.2.2",
6666
"@stdlib/assert-has-own-property": "^0.2.2",
67+
"@stdlib/assert-is-boolean": "^0.2.2",
6768
"@stdlib/assert-is-number": "^0.2.2",
6869
"@stdlib/console-log-each": "^0.2.2",
6970
"@stdlib/math-base-assert-is-nan": "^0.2.2",

0 commit comments

Comments
 (0)