LAST TEST! Use the Rest Operator with Function Parameters

Tell us what’s happening:

The last test, The sum function uses the ... spread operator on the args parameter. is failing even though sum indeed uses spread operator.

Any thoughts?

Your code so far

const sum = (...args) => !args.length ? 0 : args.reduce((a, b) => a + b);

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

Your browser information:

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

Link to the challenge:

function sum(...args) {
  return !args.length ? 0 : args.reduce((a, b) => a + b);

The test will fail if you use a function expression -

testString: getUserInput => assert(getUserInput('index').match(/function\s+sum\s*\(\s*...args\s*\)\s*{/g), 'The <code>sum</code> function uses the <code>...</code> spread operator on the <code>args</code> parameter.');

In the test, it’s looking for function sum(...args). Your code is actually fine, it just doesn’t match what the test wants

1 Like