From c1776d5788411f89da09725b048522eacf60f9b6 Mon Sep 17 00:00:00 2001
From: Ali Helmi 1.4 : New ES5
right to left and returning a final value.Array
Methods
-// add up numbers in array from left to right i.e. (((2+5) +5 ) + 5)
+// add up numbers in array from right to left i.e. (((2+5) +5 ) + 5)
var reduceRightMethod = [5, 5, 5, 2].reduceRight(function(accumulator, value, valueIndex, wholeArray){
return accumulator + value;
});
@@ -351,7 +351,7 @@ 1.4 : New ES5 Array
Methods
/** reduce also accepts a second parameter that sets the first accumulator value,
instead of using the first value in the array. **/
-// add up numbers in array from left to right, but start at 10 i.e. ((((10+2) + 5 ) +5 ) + 5)
+// add up numbers in array from right to left, but start at 10 i.e. ((((10+2) + 5 ) +5 ) + 5)
var reduceRightMethod = [5, 5, 5, 2].reduceRight(function(accumulator, value, valueIndex, wholeArray){
return accumulator + value; // first iteration of func accumulator is 10 not 5
}, 10);