The Rest and Spread Operators
Hi. I've been trying to multiply all elements of an array using the Rest and Spread Operators. It seems like it is impossible when I really breakdown the process in my head. I just want to be sure either I'm the limit or the language is.
Here is something I tried using the Array.reduce method.
//Function that multiplies the array using the rest operator to take in args
function multiply(...args){
Using the reduce function to multiply each element
args.reduce((a,b)=> console.log(a*b));
};
//Variable pointing to the array
var list = [1,2,3,4,5];
//calling the function
multiply(...list);
NAN kept getting logged