JavaScript typedArray.reduceRight() Method
Last Updated :
10 Feb, 2023
The typedArray.reduceRight() is an inbuilt function in JavaScript which is used to reduce each element of the typedArray from right to left into a single value.
Syntax:
typedArray.reduceRight(callback)
Parameters: It accept a parameter callback function which accept some parameters specified below-
- previousValue: It is the previously returned value.
- currentValue: It is the current element being processed in the typedArray.
Return value: It returns the result of the reduceRight() function.
Example:
javascript
const A = new Uint8Array([ 1, 2, 3, 4]);
const B = new Uint8Array([5, 6, 7]);
const C = new Uint8Array([1, 3, 5]);
const D = new Uint8Array([2, 4, 6, 8]);
function sum(previousValue, currentValue) {
return previousValue + currentValue;
}
console.log(A.reduceRight(sum));
console.log(B.reduceRight(sum));
console.log(C.reduceRight(sum));
console.log(D.reduceRight(sum));
|
Output:
10
18
9
20
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...