diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index 9e7ea549f00d..b076009dc4c5 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -316,6 +316,64 @@ The returned [iterator][mdn-iterator-protocol] protocol-compliant object has the - **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. - **return**: function which closes an [iterator][mdn-iterator-protocol] and returns a single (optional) argument in an [iterator][mdn-iterator-protocol] protocol-compliant object. + + +#### Uint64Array.prototype.every( predicate\[, thisArg] ) + +Returns a boolean indicating whether all elements pass a test. + +```javascript +var isEven = require( '@stdlib/assert/is-even' ); +var Number = require( '@stdlib/number/ctor' ); + +function predicate( v ) { + return ( isEven( Number( v ) ) ); +} + +var arr = new Uint64Array( 3 ); + +// Set the first three elements: +arr.set( 2, 0 ); +arr.set( 4, 1 ); +arr.set( 6, 2 ); + +// Check whether all elements pass a test: +var bool = arr.every( predicate ); +// returns true +``` + +The `predicate` function is provided three arguments: + +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +To set the function execution context, provide a `thisArg`. + +```javascript +function predicate( v, i ) { + this.count += 1; + return ( i >= 0 ); +} + +var arr = new Uint64Array( 3 ); + +var context = { + 'count': 0 +}; + +// Set the first three elements: +arr.set( 2, 0 ); +arr.set( 4, 1 ); +arr.set( 6, 2 ); + +var bool = arr.every( predicate, context ); +// returns true + +var count = context.count; +// returns 3 +``` + #### Uint64Array.prototype.get( i ) diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.js new file mode 100644 index 000000000000..927946017bb3 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.js @@ -0,0 +1,84 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var isEven = require( '@stdlib/assert/is-even' ); +var Number = require( '@stdlib/number/ctor' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:every', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Uint64Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +bench( format( '%s::this_context:every', pkg ), function benchmark( b ) { + var bool; + var arr; + var i; + + arr = new Uint64Array( 2 ); + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate, {} ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.length.js new file mode 100644 index 000000000000..3a10c110342c --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.every.length.js @@ -0,0 +1,108 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var format = require( '@stdlib/string/format' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var isEven = require( '@stdlib/assert/is-even' ); +var Number = require( '@stdlib/number/ctor' ); +var pow = require( '@stdlib/math/base/special/pow' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* Returns a boolean indicating whether an array element passes a test. +* +* @private +* @param {*} value - value to test +* @returns {boolean} boolean indicating whether an array element passes a test +*/ +function predicate( value ) { + return ( isEven( Number( value ) ) ); +} + +/** +* Creates a benchmark function. +* +* @private +* @param {PositiveInteger} len - array length +* @returns {Function} benchmark function +*/ +function createBenchmark( len ) { + var arr = new Uint64Array( len ); + return benchmark; + + /** + * Benchmark function. + * + * @private + * @param {Benchmark} b - benchmark instance + */ + function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + bool = arr.every( predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); + } +} + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var len; + var min; + var max; + var f; + var i; + + min = 1; // 10^min + max = 6; // 10^max + + for ( i = min; i <= max; i++ ) { + len = pow( 10, i ); + f = createBenchmark( len ); + bench( format( '%s:every:len=%d', pkg, len ), f ); + } +} + +main(); diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index 6dd3c27d5987..61068153dd05 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -275,6 +275,39 @@ true +{{alias}}.prototype.every( predicate[, thisArg] ) + Returns a boolean indicating whether all elements in the array pass a test. + + A predicate function is provided the following arguments: + + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + Parameters + ---------- + predicate: Function + Predicate function which tests array elements. If a predicate function + returns a truthy value, an array element passes; otherwise, an array + element fails. + + thisArg: any (optional) + Execution context. + + Returns + ------- + bool: boolean + Boolean indicating whether all elements pass the test. + + Examples + -------- + > function predicate( v ) {return({{alias:@stdlib/assert/is-uint64}}(v));}; + > var arr = new {{alias}}( [ 2, 4, 6 ] ) + + > var bool = arr.every( predicate ) + true + + {{alias}}.prototype.get( i ) Returns an array element located at integer position (index) `i`. diff --git a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts index 73e7941a80c5..e2b21a3e45c3 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/array/uint64/docs/types/index.d.ts @@ -459,6 +459,32 @@ declare class Uint64Array implements Uint64ArrayInterface { */ entries(): TypedIterator<[number, Uint64]>; + /** + * Tests whether all elements in an array pass a test implemented by a predicate function. + * + * @param predicate - test function + * @param thisArg - execution context + * @returns boolean indicating whether all elements pass a test + * + * @example + * var isEven = require( '@stdlib/assert/is-even' ); + * var Number = require( '@stdlib/number/ctor' ); + * + * function predicate( v ) { + * return ( isEven( Number( v ) ) ); + * } + * + * var arr = new Uint64Array( 3 ); + * + * arr.set( 2, 0 ); + * arr.set( 4, 1 ); + * arr.set( 6, 2 ); + * + * var bool = arr.every( predicate ); + * // returns true + */ + every( predicate: Predicate, thisArg?: ThisParameterType> ): boolean; + /** * Returns an array element. * diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index e366fe395f55..141a76e3349d 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -709,6 +709,53 @@ setReadOnly( Uint64Array.prototype, 'entries', function entries() { } }); +/** +* Tests whether all elements in an array pass a test implemented by a predicate function. +* +* @name every +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} predicate - test function +* @param {*} [thisArg] - predicate function execution context +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @returns {boolean} boolean indicating whether all elements pass a test +* +* @example +* var isEven = require( '@stdlib/assert/is-even' ); +* var Number = require( '@stdlib/number/ctor' ); +* +* function predicate( v ) { +* return ( isEven( Number( v ) ) ); +* } +* +* var arr = new Uint64Array( 3 ); +* +* arr.set( 2, 0 ); +* arr.set( 4, 1 ); +* arr.set( 6, 2 ); +* +* var bool = arr.every( predicate ); +* // returns true +*/ +setReadOnly( Uint64Array.prototype, 'every', function every( predicate, thisArg ) { + var buf; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( predicate ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', predicate ) ); + } + buf = this._buffer; + for ( i = 0; i < this._length; i++ ) { + if ( !predicate.call( thisArg, getUint64( buf, i ), i, this ) ) { + return false; + } + } + return true; +}); + /** * Returns an array element. * diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.every.js b/lib/node_modules/@stdlib/array/uint64/test/test.every.js new file mode 100644 index 000000000000..f7ba72ec53ac --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.every.js @@ -0,0 +1,175 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isEven = require( '@stdlib/assert/is-even' ); +var isFunction = require( '@stdlib/assert/is-function' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64Array = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof Uint64Array, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'attached to the prototype of the main export is an `every` method for returning boolean indicating whether all elements pass a test', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'every' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.every ), true, 'has method' ); + t.end(); +}); + +tape( 'the method throws an error if invoked with a `this` context which is not a 64-bit unsigned integer instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 5, + NaN, + true, + false, + null, + void 0, + {}, + [], + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.every.call( value, predicate ); + }; + } + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method throws an error if provided a first argument which is not a function', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + {}, + [] + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + return arr.every( value ); + }; + } +}); + +tape( 'the method returns `true` if operating on an empty 64-bit unsigned integer array', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array(); + bool = arr.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate() { + t.fail( 'should not be invoked' ); + } +}); + +tape( 'the method returns `true` if all elements pass a test', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 2, 2, 2, 2 ] ); + bool = arr.every( predicate ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method returns `false` if one or more elements fail a test', function test( t ) { + var bool; + var arr; + + arr = new Uint64Array( [ 2, 4, 5, 7 ] ); + bool = arr.every( predicate ); + + t.strictEqual( bool, false, 'returns expected value' ); + t.end(); + + function predicate( v ) { + return ( isEven( Number( v ) ) ); + } +}); + +tape( 'the method supports providing an execution context', function test( t ) { + var bool; + var ctx; + var arr; + + ctx = { + 'count': 0 + }; + arr = new Uint64Array( [ 2, 4, 6 ] ); + bool = arr.every( predicate, ctx ); + + t.strictEqual( bool, true, 'returns expected value' ); + t.strictEqual( ctx.count, 3, 'returns expected value' ); + + t.end(); + + function predicate( v ) { + this.count += 1; // eslint-disable-line no-invalid-this + return ( isEven( Number( v ) ) ); + } +});