reduceRight Summary Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. Signatures Click on a signature to select it and view its documentation. public T reduceRight(T(T previousValue) callback) public T reduceRight(T(T previousValue) callback, T initialValue) public T reduceRight(T(T previousValue, T currentValue) callback) public ResT reduceRight(ResT(ResT previousValue, T currentValue) callback, ResT initialValue) public T reduceRight(T(T previousValue, T currentValue, int index) callback) public ResT reduceRight(ResT(ResT previousValue, T currentValue, int index) callback, ResT initialValue) public T reduceRight(T(T previousValue, T currentValue, int index, T[] array) callback) public ResT reduceRight(ResT(ResT previousValue, T currentValue, int index, T[] array) callback, ResT initialValue) Usage public T reduceRight(T(T previousValue) callback) public T reduceRight(T(T previousValue) callback, T initialValue) public T reduceRight(T(T previousValue, T currentValue) callback) public ResT reduceRight(ResT(ResT previousValue, T currentValue) callback, ResT initialValue) public T reduceRight(T(T previousValue, T currentValue, int index) callback) public ResT reduceRight(ResT(ResT previousValue, T currentValue, int index) callback, ResT initialValue) public T reduceRight(T(T previousValue, T currentValue, int index, T[] array) callback) public ResT reduceRight(ResT(ResT previousValue, T currentValue, int index, T[] array) callback, ResT initialValue) Returns The reduced value. The reduced value. The reduced value. The reduced value. The reduced value. The reduced value. The reduced value. The reduced value. Parameters callback A function which provides the operation logic. Parameters callback A function which provides the operation logic. initialValue The value to apply to the first iteration. Parameters callback A function which provides the operation logic. Parameters callback A function which provides the operation logic. initialValue The value to apply to the first iteration. Parameters callback A function which provides the operation logic. Parameters callback A function which provides the operation logic. initialValue The value to apply to the first iteration. Parameters callback A function which provides the operation logic. Parameters callback A function which provides the operation logic. initialValue The value to apply to the first iteration. Description Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Applies an accumulator function (on each array element from right to left) to reduce the array to a single value. This method was standardized in ECMAScript 5 for JavaScript. For web browsers that do not support ECMAScript 5, JS++ will provide a polyfill for this method only if it is used. Examples Sum all values 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int sum = numbers.reduceRight(int(int previousValue, int currentValue) { return previousValue + currentValue;});Console.log(sum); // 30 Sum all values 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int sum = numbers.reduceRight(int(int previousValue, int currentValue) { return previousValue + currentValue;});Console.log(sum); // 30 Sum all values plus an initial value 1234567891011import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int initialValue = 50;int sum = numbers.reduceRight( int(int previousValue, int currentValue) { return previousValue + currentValue; }, initialValue);Console.log(sum); // 80 Sum all values 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int sum = numbers.reduceRight(int(int previousValue, int currentValue) { return previousValue + currentValue;});Console.log(sum); // 30 Sum all values 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int sum = numbers.reduceRight(int(int previousValue, int currentValue) { return previousValue + currentValue;});Console.log(sum); // 30 Sum all values plus an initial value 1234567891011import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int initialValue = 50;int sum = numbers.reduceRight( int(int previousValue, int currentValue) { return previousValue + currentValue; }, initialValue);Console.log(sum); // 80 Sum all values 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int sum = numbers.reduceRight(int(int previousValue, int currentValue) { return previousValue + currentValue;});Console.log(sum); // 30 Sum all values 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int sum = numbers.reduceRight(int(int previousValue, int currentValue) { return previousValue + currentValue;});Console.log(sum); // 30 Sum all values plus an initial value 123456789101112import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int initialValue = 50;int sum = numbers.reduceRight( int(int previousValue, int currentValue, int index) { Console.log("index: " + index.toString()); return previousValue + currentValue; }, initialValue);Console.log(sum); // 80 Sum all values 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int sum = numbers.reduceRight(int(int previousValue, int currentValue) { return previousValue + currentValue;});Console.log(sum); // 30 Sum all values 1234567import System; int[] numbers = [ 2, 4, 6, 8, 10 ];int sum = numbers.reduceRight(int(int previousValue, int currentValue) { return previousValue + currentValue;});Console.log(sum); // 30 Sum all values plus an initial value 12345678910111213import System;import System.Assert; int[] numbers = [ 2, 4, 6, 8, 10 ];int initialValue = 50;int sum = numbers.reduceRight( int(int previousValue, int currentValue, int index, int[] array) { assert(currentValue == array[index]); return previousValue + currentValue; }, initialValue);Console.log(sum); // 80 Share HTML | BBCode | Direct Link