Rest paramenters and es6

Tell us what’s happening:
anyone who will help to carry out this challange…

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

  const args = [x, y, z];

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

}

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

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

Your code so far


const sum = (...args) => {
const args = [x, y, z];
return args.reduce((a, b) => a + b, 0);
}
console.log(sum(1, 2, 3));
console.log(sum(1, 2, 5,));

i didnt get where i am getting wrong

Your browser information:

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

Challenge: Use the Rest Parameter with Function Parameters

Link to the challenge:

you are overwriting the parameter with an array containing undeclared variables

do you see anything in the console before running the tests?


I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

not at all. akay i will do it for the next time. i will take care

if I copy your code and paste it in the editor I get:

SyntaxError: unknown: Identifier 'args' has already been declared

Tell us what’s happening:
function sum(…args) {

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

}

console.log(sum(2,3,4,5,6,6,7,8,3));

Your code so far


function sum(...args) {
return args.reduce((a,b) => a+b,0);
}

console.log(sum(2,3,4,5,6,6,7,8,3));

what the … error is here telling me
The sum function should use the ... rest parameter on the args parameter.
Your browser information:

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

Challenge: Use the Rest Parameter with Function Parameters

Link to the challenge:

you still need to use arrow function here, you have changed too much

check the below code:
function sum(…args) {
return args.reduce((a,b) => a+b, 0;);
}
The above code passess all the tests specified but, still says , make sure to use the args parameter as a rest parameter. Which is the last test. You may change the last test, as it gives the error without any reason or the logic behind the test is not true, as you can see in the above code i have used the args parameter as a rest parameter. Try to run the above code.

the starting code uses an arrow function, you have changed too much

Please sir make sure to change the last test . It is useless or maybe it is not required anymore as the problem specified really tells us to use the rest parameter.

please read what I am writing, the starting code uses arrow function, like this:

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

if you do more than the challenge asks for, in this case changing the arrow function to use the function keyword, you can’t pretend the tests to work

I am done with the problem, yeah your solution really works but the last test does not tells to use the arrow function, instead it creates confusion as it sends the error message about the rest parameter. So you must change it.

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

Ok Sir, got it. Thanks for your help.

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