Rest Parameter question

I have fulfilled on condition with regards to this question, but why do I fail the condition for using the rest parameter?

const sum = (...num) => {
const args = num;
return args.reduce((a, b) => a + b, 0);
  **Your browser information:**

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

Challenge: Use the Rest Parameter with Function Parameters

Link to the challenge:

That last condition require you to use args as the name of the parameter :slight_smile:

const sum = (...args) => { 

HAHAHAH this was so unexpected, thanks man. I wish they’d be more clear about it but it makes for a fun problem solving exercise.

HAHAH I can’t believe that was it. But it’s weird because they declared a const variable with args already, meaning that if I used args in the parameter there would be an error.

well, you need to delete that line.

const sum = (x, y, z) => {
  const args = [x, y, z];
  return args.reduce((a, b) => a + b, 0);

The point is that you have to refactor this function, so that instead of creating the const args you use it as function parameter :slight_smile:

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.