Skip to content

Commit 998f88b

Browse files
committed
Auto-generated commit
1 parent d192758 commit 998f88b

11 files changed

Lines changed: 521 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
### Features
1212

13+
- [`7d36694`](https://github.com/stdlib-js/stdlib/commit/7d366942eabec37ee94a7e958c76de4b0bec9477) - add `every` method to `array/uint64` [(#14146)](https://github.com/stdlib-js/stdlib/pull/14146)
1314
- [`7d6191b`](https://github.com/stdlib-js/stdlib/commit/7d6191b9dc76d9f4aeefccb43672ed2fd81384f2) - add `copyWithIn` method to `array/uint64` [(#13940)](https://github.com/stdlib-js/stdlib/pull/13940)
1415
- [`b5ff3b6`](https://github.com/stdlib-js/stdlib/commit/b5ff3b66fe639b073761be77dfe1a3b57773d6f6) - add `entries` method to `array/uint64` [(#13888)](https://github.com/stdlib-js/stdlib/pull/13888)
1516
- [`24405b6`](https://github.com/stdlib-js/stdlib/commit/24405b647f170b8737700ebc9d08752bd5cc1ea5) - add `at` method to `array/uint64` [(#13830)](https://github.com/stdlib-js/stdlib/pull/13830)
@@ -35,6 +36,7 @@
3536

3637
<details>
3738

39+
- [`7d36694`](https://github.com/stdlib-js/stdlib/commit/7d366942eabec37ee94a7e958c76de4b0bec9477) - **feat:** add `every` method to `array/uint64` [(#14146)](https://github.com/stdlib-js/stdlib/pull/14146) _(by Divit Jain)_
3840
- [`7d6191b`](https://github.com/stdlib-js/stdlib/commit/7d6191b9dc76d9f4aeefccb43672ed2fd81384f2) - **feat:** add `copyWithIn` method to `array/uint64` [(#13940)](https://github.com/stdlib-js/stdlib/pull/13940) _(by Divit Jain)_
3941
- [`78ad2fa`](https://github.com/stdlib-js/stdlib/commit/78ad2fa5dbb12ce808dec93197d5343745ff91b8) - **docs:** normalize trailing newlines in REPL help texts [(#16420)](https://github.com/stdlib-js/stdlib/pull/16420) _(by Philipp Burckhardt)_
4042
- [`a800ae0`](https://github.com/stdlib-js/stdlib/commit/a800ae09acaf3af1ddc728ed50228189181795a7) - **docs:** fix examples and notes [(#16144)](https://github.com/stdlib-js/stdlib/pull/16144) _(by Philipp Burckhardt)_

‎README.md‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,54 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the
376376
- **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.
377377
- **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object.
378378

379+
<a name="method-every"></a>
380+
381+
#### Uint64Array.prototype.every( predicate\[, thisArg] )
382+
383+
Returns a boolean indicating whether all elements pass a test.
384+
385+
```javascript
386+
var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;
387+
var Number = require( '@stdlib/number-ctor' );
388+
389+
function predicate( v ) {
390+
return ( isEven( Number( v ) ) );
391+
}
392+
393+
var arr = new Uint64Array( [ 2, 4, 6 ] );
394+
395+
// Check whether all elements pass a test:
396+
var bool = arr.every( predicate );
397+
// returns true
398+
```
399+
400+
The `predicate` function is provided three arguments:
401+
402+
- **value**: current array element.
403+
- **index**: current array element index.
404+
- **arr**: the array on which this method was called.
405+
406+
To set the function execution context, provide a `thisArg`.
407+
408+
```javascript
409+
function predicate( v, i ) {
410+
this.count += 1;
411+
return ( i >= 0 );
412+
}
413+
414+
var arr = new Uint64Array( [ 2, 4, 6 ] );
415+
416+
var context = {
417+
'count': 0
418+
};
419+
420+
var bool = arr.every( predicate, context );
421+
// returns true
422+
423+
var count = context.count;
424+
// returns 3
425+
```
426+
379427
<a name="method-get"></a>
380428

381429
#### Uint64Array.prototype.get( i )

‎benchmark/benchmark.every.js‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 isUint64 = require( '@stdlib/assert-is-uint64' );
25+
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
26+
var format = require( '@stdlib/string-format' );
27+
var pkg = require( './../package.json' ).name;
28+
var Uint64Array = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( format( '%s:every', pkg ), function benchmark( b ) {
34+
var bool;
35+
var arr;
36+
var i;
37+
38+
arr = new Uint64Array( 10 );
39+
40+
// Benchmark worst case scenario (i.e., the predicate passes for every element, so the method cannot exit early)...
41+
b.tic();
42+
for ( i = 0; i < b.iterations; i++ ) {
43+
bool = arr.every( predicate );
44+
if ( typeof bool !== 'boolean' ) {
45+
b.fail( 'should return a boolean' );
46+
}
47+
}
48+
b.toc();
49+
if ( !isBoolean( bool ) ) {
50+
b.fail( 'should return a boolean' );
51+
}
52+
b.pass( 'benchmark finished' );
53+
b.end();
54+
55+
function predicate( v ) {
56+
return isUint64( v );
57+
}
58+
});
59+
60+
bench( format( '%s::this_context:every', pkg ), function benchmark( b ) {
61+
var bool;
62+
var arr;
63+
var i;
64+
65+
arr = new Uint64Array( 10 );
66+
67+
// Benchmark worst case scenario (i.e., the predicate passes for every element, so the method cannot exit early)...
68+
b.tic();
69+
for ( i = 0; i < b.iterations; i++ ) {
70+
bool = arr.every( predicate, {} );
71+
if ( typeof bool !== 'boolean' ) {
72+
b.fail( 'should return a boolean' );
73+
}
74+
}
75+
b.toc();
76+
if ( !isBoolean( bool ) ) {
77+
b.fail( 'should return a boolean' );
78+
}
79+
b.pass( 'benchmark finished' );
80+
b.end();
81+
82+
function predicate( v ) {
83+
return isUint64( v );
84+
}
85+
});
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 isUint64 = require( '@stdlib/assert-is-uint64' );
26+
var isBoolean = require( '@stdlib/assert-is-boolean' ).isPrimitive;
27+
var format = require( '@stdlib/string-format' );
28+
var pkg = require( './../package.json' ).name;
29+
var Uint64Array = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Predicate function.
36+
*
37+
* @private
38+
* @param {Uint64} value - array element
39+
* @returns {boolean} boolean indicating whether a value passes a test
40+
*/
41+
function predicate( value ) {
42+
return isUint64( value );
43+
}
44+
45+
/**
46+
* Creates a benchmark function.
47+
*
48+
* @private
49+
* @param {PositiveInteger} len - array length
50+
* @returns {Function} benchmark function
51+
*/
52+
function createBenchmark( len ) {
53+
var arr = new Uint64Array( len );
54+
return benchmark;
55+
56+
/**
57+
* Benchmark function.
58+
*
59+
* @private
60+
* @param {Benchmark} b - benchmark instance
61+
*/
62+
function benchmark( b ) {
63+
var bool;
64+
var i;
65+
66+
// Benchmark worst case scenario (i.e., the predicate passes for every element, so the method cannot exit early)...
67+
b.tic();
68+
for ( i = 0; i < b.iterations; i++ ) {
69+
bool = arr.every( predicate );
70+
if ( typeof bool !== 'boolean' ) {
71+
b.fail( 'should return a boolean' );
72+
}
73+
}
74+
b.toc();
75+
if ( !isBoolean( bool ) ) {
76+
b.fail( 'should return a boolean' );
77+
}
78+
b.pass( 'benchmark finished' );
79+
b.end();
80+
}
81+
}
82+
83+
84+
// MAIN //
85+
86+
/**
87+
* Main execution sequence.
88+
*
89+
* @private
90+
*/
91+
function main() {
92+
var len;
93+
var min;
94+
var max;
95+
var f;
96+
var i;
97+
98+
min = 1; // 10^min
99+
max = 6; // 10^max
100+
101+
for ( i = min; i <= max; i++ ) {
102+
len = pow( 10, i );
103+
f = createBenchmark( len );
104+
bench( format( '%s:every:len=%d', pkg, len ), f );
105+
}
106+
}
107+
108+
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.

‎docs/repl.txt‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,38 @@
302302
true
303303

304304

305+
{{alias}}.prototype.every( predicate[, thisArg] )
306+
Returns a boolean indicating whether all elements in the array pass a test.
307+
308+
A predicate function is provided the following arguments:
309+
310+
- value: current array element.
311+
- index: current array element index.
312+
- arr: the array on which the method was called.
313+
314+
Parameters
315+
----------
316+
predicate: Function
317+
Predicate function which tests array elements. If a predicate function
318+
returns a truthy value, an array element passes; otherwise, an array
319+
element fails.
320+
321+
thisArg: any (optional)
322+
Execution context.
323+
324+
Returns
325+
-------
326+
bool: boolean
327+
Boolean indicating whether all elements pass the test.
328+
329+
Examples
330+
--------
331+
> function predicate( v ) { return ( {{alias:@stdlib/assert/is-even}}.isPrimitive( {{alias:@stdlib/number/ctor}}( v ) ) ); };
332+
> var arr = new {{alias}}( [ 2, 4, 6 ] );
333+
> var bool = arr.every( predicate )
334+
true
335+
336+
305337
{{alias}}.prototype.get( i )
306338
Returns an array element located at integer position (index) `i`.
307339

‎docs/types/index.d.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,28 @@ declare class Uint64Array implements Uint64ArrayInterface {
471471
*/
472472
entries(): TypedIterator<[number, Uint64]>;
473473

474+
/**
475+
* Tests whether all elements in an array pass a test implemented by a predicate function.
476+
*
477+
* @param predicate - test function
478+
* @param thisArg - execution context
479+
* @returns boolean indicating whether all elements pass a test
480+
*
481+
* @example
482+
* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;
483+
* var Number = require( '@stdlib/number-ctor' );
484+
*
485+
* function predicate( v ) {
486+
* return ( isEven( Number( v ) ) );
487+
* }
488+
*
489+
* var arr = new Uint64Array( [ 2, 4, 6 ] );
490+
*
491+
* var bool = arr.every( predicate );
492+
* // returns true
493+
*/
494+
every<U = unknown>( predicate: Predicate<U>, thisArg?: ThisParameterType<Predicate<U>> ): boolean;
495+
474496
/**
475497
* Returns an array element.
476498
*

‎lib/main.js‎

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,49 @@ setReadOnly( Uint64Array.prototype, 'entries', function entries() {
734734
}
735735
});
736736

737+
/**
738+
* Tests whether all elements in an array pass a test implemented by a predicate function.
739+
*
740+
* @name every
741+
* @memberof Uint64Array.prototype
742+
* @type {Function}
743+
* @param {Function} predicate - test function
744+
* @param {*} [thisArg] - predicate function execution context
745+
* @throws {TypeError} `this` must be a 64-bit unsigned integer array
746+
* @throws {TypeError} first argument must be a function
747+
* @returns {boolean} boolean indicating whether all elements pass a test
748+
*
749+
* @example
750+
* var isEven = require( '@stdlib/assert-is-even' ).isPrimitive;
751+
* var Number = require( '@stdlib/number-ctor' );
752+
*
753+
* function predicate( v ) {
754+
* return ( isEven( Number( v ) ) );
755+
* }
756+
*
757+
* var arr = new Uint64Array( [ 2, 4, 6 ] );
758+
*
759+
* var bool = arr.every( predicate );
760+
* // returns true
761+
*/
762+
setReadOnly( Uint64Array.prototype, 'every', function every( predicate, thisArg ) {
763+
var buf;
764+
var i;
765+
if ( !isUint64Array( this ) ) {
766+
throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' );
767+
}
768+
if ( !isFunction( predicate ) ) {
769+
throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) );
770+
}
771+
buf = this._buffer;
772+
for ( i = 0; i < this._length; i++ ) {
773+
if ( !predicate.call( thisArg, getUint64( buf, i ), i, this ) ) {
774+
return false;
775+
}
776+
}
777+
return true;
778+
});
779+
737780
/**
738781
* Returns an array element.
739782
*

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@
6969
"@stdlib/assert-has-bigint-support": "^0.2.3",
7070
"@stdlib/assert-has-own-property": "^0.2.3",
7171
"@stdlib/assert-is-array": "^0.2.3",
72+
"@stdlib/assert-is-boolean": "^0.2.3",
7273
"@stdlib/assert-is-equal-uint64array": "github:stdlib-js/assert-is-equal-uint64array#main",
74+
"@stdlib/assert-is-even": "^0.2.3",
7375
"@stdlib/assert-is-uint64array": "github:stdlib-js/assert-is-uint64array#main",
7476
"@stdlib/bigint-ctor": "^0.2.3",
7577
"@stdlib/console-log-each": "^0.2.4",

0 commit comments

Comments
 (0)