-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathreduceRight.js
39 lines (32 loc) · 1.4 KB
/
reduceRight.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
// TOPIC /////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Array Method: .reduceRight()
//
// SYNTAX ////////////////////////////////////////////////////////////////////////////////////////////////////
//
// array.reduceRight(previousValue, currentValue)
//
// SUMMARY ///////////////////////////////////////////////////////////////////////////////////////////////////
//
// • .reduceRight() is an inbuilt method used to convert elements of a given array from right to left to
// a single value.
// • .reduceRight() is like the .reduce() method, except it goes from the RIGHT to the LEFT.
//
// EXAMPLES //////////////////////////////////////////////////////////////////////////////////////////////////
//
// EXAMPLE 1: Use reduceRight to find the multiplied sum of the total array.
//
// RESOURCES /////////////////////////////////////////////////////////////////////////////////////////////////
//
// https://www.javascripttutorial.net/javascript-array-reduce/
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
const numbers = [1,2,3,4,5,6]
function reduceIt() {
let nums = numbers.reduceRight(function (prev, curr) {
return prev * curr;
});
console.log(nums)
}
reduceIt(); // 720 (i.e. 6 * 5 * 4 * 3 * 2 * 1)