Solve rest operators

Modify the function sum using the rest parameter in such a way that the function sum is able to take any number of arguments and return their sum.

The result of sum(0,1,2) should be 3

Passed

The result of sum(1,2,3,4) should be 10

The result of sum(5) should be 5

The result of sum() should be 0

The sum function should use the ... rest parameter on the args parameter.

const sum = (x, y, z) => {

const args = [x, y, z];

return args.reduce((a, b) => a + b, 4);

}

console.log(sum(0,1, 2));

console.log(sum(1, 2, 3));

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36.

Challenge: Use the Rest Parameter with Function Parameters

Link to the challenge:

here you are setting 4 as starting value of the reduce function, you should not set a starting value or all the results would be skewed - you do not even need to change the reduce function

the thing you need to change is here:

where args should be the function parameter, with the rest operator
so that it can work with any number of parameters.