I need to create a function, that will parse function parameter of integer to an array list.
So if we call the function like this: sum(1, 4 ,7);
then inside of the function 'sum' the arguments variable/keyword will look like this [1, 4, 7].
I need to create a sum function so that it can take any number of arguments and return the sum of all of them.
Here's my code so far:
function sum ([a,b]) {
var arr = [a,b];
var sum =arr.reduce(add, 0);
function add(a, b) {
return a + b;
}
}
I also was trying to so something like this:
function sum ({
arr[0]: 1;
arr[1]: 2;
arr[2]:3;
var sum =arr.reduce(add, 0);
function add(a, b) {
return a + b;
}
})
but I obviously doing something wrong.