The reduceRight
method executes the callbackFn
function once for each element present in the typed array, excluding holes in the typed array, receiving four arguments: the initial value (or value from the previous callbackFn
call), the value of the current element, the current index, and the typed array over which iteration is occurring.
The call to the reduceRight
callback would look something like this:
typedarray.reduceRight((accumulator, currentValue, index, typedarray) => {
});
The first time the function is called, the accumulator
and currentValue
can be one of two values. If an initialValue
was provided in the call to reduceRight
, then accumulator
will be equal to initialValue
and currentValue
will be equal to the last value in the typed array. If no initialValue
was provided, then accumulator
will be equal to the last value in the typed array and currentValue
will be equal to the second-to-last value.
If the typed array is empty and no initialValue
was provided, TypeError
would be thrown. If the typed array has only one element (regardless of position) and no initialValue
was provided, or if initialValue
is provided but the typed array is empty, the solo value would be returned without calling callbackFn
.