ES6 - Use the Rest Parameter with Function Parameters

Tell us what’s happening:

const sum = (…n) => {
const args = n;
let total = 0;
for (let i = 0; i < args.length; i++) {
total += args[i];
}
return total;
}

Your code so far

I’m getting the desired output, but I’m not sure why it’s not passing the last test.

const sum = (...n) => {
  const args = n;
  let total = 0;
  for (let i = 0; i < args.length; i++) {
    total += args[i];
  }
  return total;
}

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36

Challenge Information:

ES6 - Use the Rest Parameter with Function Parameters

you can directly use the rest parameter without assigning it to another variable:

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

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