From 9fc37a18314da14d18cfa3f9bf68d938228f5f88 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Tue, 6 Oct 2026 03:53:08 +0000 Subject: [PATCH 01/11] feat: add reduce method for array/uint64 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/array/uint64/lib/main.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 8c6c391a29c4..186d33aff9c6 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -1566,6 +1566,58 @@ setReadOnly( Uint64Array.prototype, 'map', function map( fcn, thisArg ) { return out; }); +/** +* Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. +* +* @name reduce +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} reducer - callback function +* @param {*} [initialValue] - initial value +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @throws {Error} if not provided an initial value, the array must have at least one element +* @returns {*} accumulated result +* +* @example +* var add = require( '@stdlib/number/uint64/base/add' ); +* +* var arr = new Uint64Array( [ 1, 2, 3 ] ); +* +* var u = arr.reduce( add ); +* // returns [ 6n ] +*/ +setReadOnly( Uint64Array.prototype, 'reduce', function reduce( reducer, initialValue ) { + var buf; + var acc; + var len; + var v; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( reducer ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + } + buf = this._buffer; + len = this._length; + if ( arguments.length > 1 ) { + acc = initialValue; + i = 0; + } else { + if ( len === 0 ) { + throw new Error( 'invalid operation. If not provided an initial value, an array must contain at least one element.' ); + } + acc = getUint64( buf, 0 ); + i = 1; + } + for ( ; i < len; i++ ) { + v = getUint64( buf, i ); + acc = reducer( acc, v, i, this ); + } + return acc; +}); + /** * Sets an array element. * From 2b087f1df1eeb6f0548401f1ba87985cd81ea881 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Tue, 6 Oct 2026 04:01:55 +0000 Subject: [PATCH 02/11] test: add test --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/array/uint64/test/test.reduce.js | 204 ++++++++++++++++++ 1 file changed, 204 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/test/test.reduce.js diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.reduce.js b/lib/node_modules/@stdlib/array/uint64/test/test.reduce.js new file mode 100644 index 000000000000..07d31060422a --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.reduce.js @@ -0,0 +1,204 @@ +/** +* @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 isFunction = require( '@stdlib/assert/is-function' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/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 a `reduce` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'reduce' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.reduce ), 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 array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 5, + 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.reduce.call( value, add ); + }; + } +}); + +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( 5 ); + + values = [ + '5', + 5, + 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.reduce( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an initial value when operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + + arr = new Uint64Array( 0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + arr.reduce( add ); + } +}); + +tape( 'the method uses the first element of the array as the initial value when an initial value is not provided', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + accArray = [ 1, 3 ]; + valueArray = [ 2, 3 ]; + expected = new Uint64( 6 ); + actual = arr.reduce( reducer ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + + t.end(); + + function reducer( acc, value, index ) { + var ind = index - 1; + t.strictEqual( isUint64( acc ), true, 'returns expected value' ); + t.strictEqual( isEqual( acc, new Uint64( accArray[ ind ] ) ), true, 'returns expected value' ); + t.strictEqual( isUint64( value ), true, 'returns expected value' ); + t.strictEqual( isEqual( value, new Uint64( valueArray[ ind ] ) ), true, 'returns expected value' ); + return add( acc, value ); + } +}); + +tape( 'the method supports providing an initial value as the second argument', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + accArray = [ 2, 3, 5 ]; + valueArray = [ 1, 2, 3 ]; + expected = new Uint64( 8 ); + actual = arr.reduce( reducer, new Uint64( 2 ) ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + + t.end(); + + function reducer( acc, value, index ) { + t.strictEqual( isUint64( acc ), true, 'returns expected value' ); + t.strictEqual( isEqual( acc, new Uint64( accArray[ index ] ) ), true, 'returns expected value' ); + t.strictEqual( isUint64( value ), true, 'returns expected value' ); + t.strictEqual( isEqual( value, new Uint64( valueArray[ index ] ) ), true, 'returns expected value' ); + return add( acc, value ); + } +}); + +tape( 'the method returns the accumulated result', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = new Uint64( 6 ); + actual = arr.reduce( add ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports returning real-valued results', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = 6; + actual = arr.reduce( reducer, 0 ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value ) { + return acc + Number( value ); + } +}); From 585f37aca07f2dc58646da36edbe1f3e1ce20c9d Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Tue, 6 Oct 2026 04:05:19 +0000 Subject: [PATCH 03/11] bench: add benchmarks --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../uint64/benchmark/benchmark.reduce.js | 81 ++++++++++++++++ .../benchmark/benchmark.reduce.length.js | 97 +++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js create mode 100644 lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.length.js diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js new file mode 100644 index 000000000000..b7376999c583 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js @@ -0,0 +1,81 @@ +/** +* @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 isUint64 = require( '@stdlib/assert/is-uint64' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:reduce', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( add ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::initial_value:reduce', pkg ), function benchmark( b ) { + var out; + var arr; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 0 ); + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( add, v ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.length.js new file mode 100644 index 000000000000..2336da53d722 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.length.js @@ -0,0 +1,97 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* 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 out; + var i; + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduce( add ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + 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:reduce:len=%d', pkg, len ), f ); + } +} + +main(); From 6d20da970db6ae46f726ba13778d93c9d5efc2e3 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Tue, 6 Oct 2026 04:08:50 +0000 Subject: [PATCH 04/11] feat: add `reduce` method to `array/uint64` --- .../@stdlib/array/uint64/README.md | 38 +++++++++++++++++ .../@stdlib/array/uint64/docs/repl.txt | 41 +++++++++++++++++++ .../array/uint64/docs/types/index.d.ts | 17 ++++++++ 3 files changed, 96 insertions(+) diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index cd7a0c3c60ec..426800733392 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -948,6 +948,44 @@ var count = context.count; // returns 3 ``` + + +#### Uint64Array.prototype.reduce( reducerFn\[, initialValue] ) + +Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. + +```javascript +var add = require( '@stdlib/number/uint64/base/add' ); + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var u = arr.reduce( add ); +// returns [ 6n ] +``` + +The reducer function is provided four arguments: + +- **acc**: accumulated result. +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +By default, the function initializes the accumulated result to the first element in the array and passes the second array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the first array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument. + +```javascript +var Number = require( '@stdlib/number/ctor' ); + +function reducer( acc, v ) { + acc += Number( v ); + return acc; +} + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var sum = arr.reduce( reducer, 2 ); +// returns 8 +``` + #### Uint64Array.prototype.set( value\[, i] ) diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index e445c3bd0d8d..53a26a7a8f65 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -749,6 +749,47 @@ [ 2n, 4n ] +{{alias}}.prototype.reduce( reducerFn[, initialValue] ) + Applies a provided function to each element of the array, in order, passing + in the return value from the calculation on the preceding element and + returning the accumulated result upon completion. + + A reducer function is provided the following arguments: + + - acc: accumulated result. + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + If provided an initial value, the method invokes a provided function with + the initial value as the first argument and the first array element as the + second argument. + + If not provided an initial value, the method invokes a provided function + with the first array element as the first argument and the second array + element as the second argument. + + Parameters + ---------- + reducerFn: Function + Function to apply to each array element. + + initialValue: any (optional) + Initial accumulation value. + + Returns + ------- + out: any + Accumulated result. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3 ] ) + [ 1n, 2n, 3n ] + > var u = arr.reduce( {{alias:@stdlib/number/uint64/base/add}} ) + [ 6n ] + + {{alias}}.prototype.set( v[, i] ) Sets one or more array elements. 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 518c87282546..86d8df7741c1 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 @@ -795,6 +795,23 @@ declare class Uint64Array implements Uint64ArrayInterface { */ map( fcn: MapFcn, thisArg?: ThisParameterType> ): Uint64Array; + /** + * Applies a provided callback function to each element of the array, in order, passing in the return value from the calculation on the preceding element and returning the accumulated result upon completion. + * + * @param reducer - callback function + * @param initialValue - initial value + * @returns accumulated result + * + * @example + * var add = require( '@stdlib/number/uint64/base/add' ); + * + * var arr = new Uint64Array( [ 1, 2, 3 ] ); + * + * var u = arr.reduce( add ); + * // returns [ 6n ] + */ + reduce( reducer: Reducer, initialValue?: U ): U; + /** * Sets an array element. * From e787cb8b7ffe23bfe4eaaf719222ffbc9a7bca0c Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Thu, 26 Nov 2026 04:47:39 +0000 Subject: [PATCH 05/11] chore: clean up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/array/uint64/benchmark/benchmark.reduce.js | 1 - lib/node_modules/@stdlib/array/uint64/docs/repl.txt | 3 +-- lib/node_modules/@stdlib/array/uint64/lib/main.js | 4 +--- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js index b7376999c583..a91189198895 100644 --- a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce.js @@ -61,7 +61,6 @@ bench( format( '%s::initial_value:reduce', pkg ), function benchmark( b ) { var i; arr = new Uint64Array( 10 ); - v = new Uint64( 0 ); // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index 53a26a7a8f65..22fa5ba7129c 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -784,8 +784,7 @@ Examples -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ) - [ 1n, 2n, 3n ] + > var arr = new {{alias}}( [ 1, 2, 3 ] ); > var u = arr.reduce( {{alias:@stdlib/number/uint64/base/add}} ) [ 6n ] diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 186d33aff9c6..89826f59002f 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -1591,7 +1591,6 @@ setReadOnly( Uint64Array.prototype, 'reduce', function reduce( reducer, initialV var buf; var acc; var len; - var v; var i; if ( !isUint64Array( this ) ) { throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); @@ -1612,8 +1611,7 @@ setReadOnly( Uint64Array.prototype, 'reduce', function reduce( reducer, initialV i = 1; } for ( ; i < len; i++ ) { - v = getUint64( buf, i ); - acc = reducer( acc, v, i, this ); + acc = reducer( acc, getUint64( buf, i ), i, this ); } return acc; }); From bf8ad93150b61fdc6485235f6af236c73cb55074 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Wed, 7 Oct 2026 04:34:20 +0000 Subject: [PATCH 06/11] feat: add reduceRight method for array/uint64 --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/array/uint64/lib/main.js | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index 89826f59002f..ae3b6796552d 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -1616,6 +1616,58 @@ setReadOnly( Uint64Array.prototype, 'reduce', function reduce( reducer, initialV return acc; }); +/** +* Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion. +* +* @name reduceRight +* @memberof Uint64Array.prototype +* @type {Function} +* @param {Function} reducer - callback function +* @param {*} [initialValue] - initial value +* @throws {TypeError} `this` must be a 64-bit unsigned integer array +* @throws {TypeError} first argument must be a function +* @throws {Error} if not provided an initial value, the array must have at least one element +* @returns {*} accumulated result +* +* @example +* var add = require( '@stdlib/number/uint64/base/add' ); +* +* var arr = new Uint64Array( [ 1, 2, 3 ] ); +* +* var u = arr.reduceRight( add ); +* // returns [ 6n ] +*/ +setReadOnly( Uint64Array.prototype, 'reduceRight', function reduceRight( reducer, initialValue ) { + var buf; + var acc; + var len; + var v; + var i; + if ( !isUint64Array( this ) ) { + throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); + } + if ( !isFunction( reducer ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a function. Value: `%s`.', reducer ) ); + } + buf = this._buffer; + len = this._length; + if ( arguments.length > 1 ) { + acc = initialValue; + i = len - 1; + } else { + if ( len === 0 ) { + throw new Error( 'invalid operation. If not provided an initial value, an array must contain at least one element.' ); + } + acc = getUint64( buf, len-1 ); + i = len - 2; + } + for ( ; i >= 0; i-- ) { + v = getUint64( buf, i ); + acc = reducer( acc, v, i, this ); + } + return acc; +}); + /** * Sets an array element. * From 4a3e53fce155be0c6bc860ff4097d224d7da8caf Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Wed, 7 Oct 2026 04:38:31 +0000 Subject: [PATCH 07/11] test: add test --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../array/uint64/test/test.reduce_right.js | 209 ++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/test/test.reduce_right.js diff --git a/lib/node_modules/@stdlib/array/uint64/test/test.reduce_right.js b/lib/node_modules/@stdlib/array/uint64/test/test.reduce_right.js new file mode 100644 index 000000000000..1b7a33b02c36 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/test/test.reduce_right.js @@ -0,0 +1,209 @@ +/** +* @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 isFunction = require( '@stdlib/assert/is-function' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var isEqual = require( '@stdlib/number/uint64/base/assert/is-equal' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var Number = require( '@stdlib/number/ctor' ); +var Uint64 = require( '@stdlib/number/uint64/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 a `reduceRight` method', function test( t ) { + t.strictEqual( hasOwnProp( Uint64Array.prototype, 'reduceRight' ), true, 'has property' ); + t.strictEqual( isFunction( Uint64Array.prototype.reduceRight ), 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 array instance', function test( t ) { + var values; + var arr; + var i; + + arr = new Uint64Array( 5 ); + + values = [ + '5', + 5, + 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.reduceRight.call( value, add ); + }; + } +}); + +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( 5 ); + + values = [ + '5', + 5, + 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.reduceRight( value ); + }; + } +}); + +tape( 'the method throws an error if not provided an initial value when operating on an empty 64-bit unsigned integer array', function test( t ) { + var arr; + + arr = new Uint64Array( 0 ); + t.throws( foo, Error, 'throws an error' ); + t.end(); + + function foo() { + arr.reduceRight( add ); + } +}); + +tape( 'the method uses the last element of the array as the initial value when an initial value is not provided', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + var len; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + len = arr.length; + accArray = [ 3, 5 ]; + valueArray = [ 2, 1 ]; + expected = new Uint64( 6 ); + actual = arr.reduceRight( reducer ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + + t.end(); + + function reducer( acc, value, index ) { + var ind = len - index - 2; + t.strictEqual( isUint64( acc ), true, 'returns expected value' ); + t.strictEqual( isEqual( acc, new Uint64( accArray[ ind ] ) ), true, 'returns expected value' ); + t.strictEqual( isUint64( value ), true, 'returns expected value' ); + t.strictEqual( isEqual( value, new Uint64( valueArray[ ind ] ) ), true, 'returns expected value' ); + return add( acc, value ); + } +}); + +tape( 'the method supports providing an initial value as the second argument', function test( t ) { + var valueArray; + var accArray; + var expected; + var actual; + var arr; + var len; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + len = arr.length; + accArray = [ 2, 5, 7 ]; + valueArray = [ 3, 2, 1 ]; + expected = new Uint64( 8 ); + actual = arr.reduceRight( reducer, new Uint64( 2 ) ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + + t.end(); + + function reducer( acc, value, index ) { + var ind = len - index - 1; + t.strictEqual( isUint64( acc ), true, 'returns expected value' ); + t.strictEqual( isEqual( acc, new Uint64( accArray[ ind ] ) ), true, 'returns expected value' ); + t.strictEqual( isUint64( value ), true, 'returns expected value' ); + t.strictEqual( isEqual( value, new Uint64( valueArray[ ind ] ) ), true, 'returns expected value' ); + return add( acc, value ); + } +}); + +tape( 'the method returns the accumulated result', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = new Uint64( 6 ); + actual = arr.reduceRight( add ); + + t.strictEqual( isUint64( actual ), true, 'returns expected value' ); + t.strictEqual( isEqual( actual, expected ), true, 'returns expected value' ); + t.end(); +}); + +tape( 'the method supports returning real-valued results', function test( t ) { + var expected; + var actual; + var arr; + + arr = new Uint64Array( [ 1, 2, 3 ] ); + expected = 6; + actual = arr.reduceRight( reducer, 0 ); + + t.strictEqual( actual, expected, 'returns expected value' ); + t.end(); + + function reducer( acc, value ) { + return acc + Number( value ); + } +}); From 710396bb88c6b4529ef078acdc6639df97611043 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Wed, 7 Oct 2026 04:40:21 +0000 Subject: [PATCH 08/11] bench: add benchmarks --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../benchmark/benchmark.reduce_right.js | 81 ++++++++++++++++ .../benchmark.reduce_right.length.js | 97 +++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.js create mode 100644 lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.length.js diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.js new file mode 100644 index 000000000000..a967e8d7006d --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.js @@ -0,0 +1,81 @@ +/** +* @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 isUint64 = require( '@stdlib/assert/is-uint64' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var Uint64 = require( '@stdlib/number/uint64/ctor' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// MAIN // + +bench( format( '%s:reduceRight', pkg ), function benchmark( b ) { + var out; + var arr; + var i; + + arr = new Uint64Array( 10 ); + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduceRight( add ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::initial_value:reduceRight', pkg ), function benchmark( b ) { + var out; + var arr; + var v; + var i; + + arr = new Uint64Array( 10 ); + + v = new Uint64( 0 ); + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduceRight( add, v ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.length.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.length.js new file mode 100644 index 000000000000..702f3f0874f2 --- /dev/null +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.length.js @@ -0,0 +1,97 @@ +/** +* @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 pow = require( '@stdlib/math/base/special/pow' ); +var isUint64 = require( '@stdlib/assert/is-uint64' ); +var add = require( '@stdlib/number/uint64/base/add' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var Uint64Array = require( './../lib' ); + + +// FUNCTIONS // + +/** +* 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 out; + var i; + + // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = arr.reduceRight( add ); + if ( typeof out !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isUint64( out ) ) { + b.fail( 'should return a 64-bit unsigned integer' ); + } + 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:reduceRight:len=%d', pkg, len ), f ); + } +} + +main(); From 50848dac17a0fc5b7939a0ef6665e5b5f3b8d404 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Wed, 7 Oct 2026 04:43:47 +0000 Subject: [PATCH 09/11] docs: add docs --- .../@stdlib/array/uint64/docs/repl.txt | 41 +++++++++++++++++++ .../array/uint64/docs/types/index.d.ts | 17 ++++++++ 2 files changed, 58 insertions(+) diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index 22fa5ba7129c..f9d3e518373f 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -789,6 +789,47 @@ [ 6n ] +{{alias}}.prototype.reduceRight( reducerFn[, initialValue] ) + Applies a provided function to each element of the array, in reverse order, + passing in the return value from the calculation on the preceding element + and returning the accumulated result upon completion. + + A reducer function is provided the following arguments: + + - acc: accumulated result. + - value: current array element. + - index: current array element index. + - arr: the array on which the method was called. + + If provided an initial value, the method invokes a provided function with + the initial value as the first argument and the last array element as the + second argument. + + If not provided an initial value, the method invokes a provided function + with the last array element as the first argument and the second-to-last + array element as the second argument. + + Parameters + ---------- + reducerFn: Function + Function to apply to each array element. + + initialValue: any (optional) + Initial accumulation value. + + Returns + ------- + out: any + Accumulated result. + + Examples + -------- + > var arr = new {{alias}}( [ 1, 2, 3 ] ) + [ 1n, 2n, 3n ] + > var u = arr.reduceRight( {{alias:@stdlib/number/uint64/base/add}} ) + [ 6n ] + + {{alias}}.prototype.set( v[, i] ) Sets one or more array elements. 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 86d8df7741c1..9959603f18ce 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 @@ -812,6 +812,23 @@ declare class Uint64Array implements Uint64ArrayInterface { */ reduce( reducer: Reducer, initialValue?: U ): U; + /** + * Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion. + * + * @param reducer - callback function + * @param initialValue - initial value + * @returns accumulated result + * + * @example + * var add = require( '@stdlib/number/uint64/base/add' ); + * + * var arr = new Uint64Array( [ 1, 2, 3 ] ); + * + * var u = arr.reduceRight( add ); + * // returns [ 6n ] + */ + reduceRight( reducer: Reducer, initialValue?: U ): U; + /** * Sets an array element. * From 258403d2cbfa24ce23a4df7321971d682160fa5b Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Wed, 7 Oct 2026 04:44:13 +0000 Subject: [PATCH 10/11] feat: add `reduceRight` method to `array/uint64` --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: passed - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/array/uint64/README.md | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/node_modules/@stdlib/array/uint64/README.md b/lib/node_modules/@stdlib/array/uint64/README.md index 426800733392..1998868660a7 100644 --- a/lib/node_modules/@stdlib/array/uint64/README.md +++ b/lib/node_modules/@stdlib/array/uint64/README.md @@ -986,6 +986,44 @@ var sum = arr.reduce( reducer, 2 ); // returns 8 ``` + + +#### Uint64Array.prototype.reduceRight( reducerFn\[, initialValue] ) + +Applies a provided callback function to each element of the array, in reverse order, passing in the return value from the calculation on the following element and returning the accumulated result upon completion. + +```javascript +var add = require( '@stdlib/number/uint64/base/add' ); + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var u = arr.reduceRight( add ); +// returns [ 6n ] +``` + +The reducer function is provided four arguments: + +- **acc**: accumulated result. +- **value**: current array element. +- **index**: current array element index. +- **arr**: the array on which this method was called. + +By default, the function initializes the accumulated result to the last element in the array and passes the second-last array element as `value` during the first invocation of the provided callback. To begin accumulation from a different starting value and pass in the last array element as `value` during the first invocation of the provided callback, provide an `initialValue` argument. + +```javascript +var Number = require( '@stdlib/number/ctor' ); + +function reducer( acc, v ) { + acc += Number( v ); + return acc; +} + +var arr = new Uint64Array( [ 1, 2, 3 ] ); + +var sum = arr.reduceRight( reducer, 2 ); +// returns 8 +``` + #### Uint64Array.prototype.set( value\[, i] ) From 2a31cb4705ac8d1d115884d79745f4c3ebc1e029 Mon Sep 17 00:00:00 2001 From: Divit Jain Date: Thu, 26 Nov 2026 05:09:14 +0000 Subject: [PATCH 11/11] chore: clean up --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown_pkg_readmes status: na - task: lint_markdown_docs status: na - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: passed - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- .../@stdlib/array/uint64/benchmark/benchmark.reduce_right.js | 1 - lib/node_modules/@stdlib/array/uint64/docs/repl.txt | 3 +-- lib/node_modules/@stdlib/array/uint64/lib/main.js | 4 +--- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.js b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.js index a967e8d7006d..8a778efe80b5 100644 --- a/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.js +++ b/lib/node_modules/@stdlib/array/uint64/benchmark/benchmark.reduce_right.js @@ -61,7 +61,6 @@ bench( format( '%s::initial_value:reduceRight', pkg ), function benchmark( b ) { var i; arr = new Uint64Array( 10 ); - v = new Uint64( 0 ); // Benchmark worst case scenario (i.e., every element is visited and passed to the reducer)... diff --git a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt index f9d3e518373f..deccb470b1d7 100644 --- a/lib/node_modules/@stdlib/array/uint64/docs/repl.txt +++ b/lib/node_modules/@stdlib/array/uint64/docs/repl.txt @@ -824,8 +824,7 @@ Examples -------- - > var arr = new {{alias}}( [ 1, 2, 3 ] ) - [ 1n, 2n, 3n ] + > var arr = new {{alias}}( [ 1, 2, 3 ] ); > var u = arr.reduceRight( {{alias:@stdlib/number/uint64/base/add}} ) [ 6n ] diff --git a/lib/node_modules/@stdlib/array/uint64/lib/main.js b/lib/node_modules/@stdlib/array/uint64/lib/main.js index ae3b6796552d..e1162588b507 100644 --- a/lib/node_modules/@stdlib/array/uint64/lib/main.js +++ b/lib/node_modules/@stdlib/array/uint64/lib/main.js @@ -1641,7 +1641,6 @@ setReadOnly( Uint64Array.prototype, 'reduceRight', function reduceRight( reducer var buf; var acc; var len; - var v; var i; if ( !isUint64Array( this ) ) { throw new TypeError( 'invalid invocation. `this` is not a 64-bit unsigned integer array.' ); @@ -1662,8 +1661,7 @@ setReadOnly( Uint64Array.prototype, 'reduceRight', function reduceRight( reducer i = len - 2; } for ( ; i >= 0; i-- ) { - v = getUint64( buf, i ); - acc = reducer( acc, v, i, this ); + acc = reducer( acc, getUint64( buf, i ), i, this ); } return acc; });