Tell us what’s happening:
I keep getting caught on the very last objective where I am to use the ... rest parameter on the args parameter. What do I need to do to pass that test?
I’ve tried adding the rest parameter to the original provided code by adding ... to x, y, z when the function is first being described. It does not work. Could you point me in the correct direction in more detail?
Please don’t laugh, but my first thought was very simplistic and that was just to add ... to the first variable described as shown below.
const sum = (…x, y, z) => {
const args = [x, y, z];
return args.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3)); // 6
I’ve also attempted adding ... before each of the x, y and z when sum is first defined and also when args is first defined. The code that I ultimately shared at the start of my post was the only one that could pass all the tests except the last one.
The trouble is, the example only lists one parameter in the initial definition of the function ...args. I don’t really know how to translate that onto the problem presented. Am I supposed to leave (x, y, z) alone in the solution?
I have also tried (x, y, …z) and that didn’t seem to work either.
I don’t understand your original correction then. If I don’t need to separately declare args as a variable, then what is the problem with the original code?