Hi,
My code works only in these two: " The result of sum(0,1,2)
should be 3" and " he result of sum(1,2,3,4)
should be 10".
Everything else is wrong, I mean these parts:
" The result of sum()
should be 0".
" The result of sum(5)
should be 5".
" The sum
function uses the ...
spread operator on the args
parameter.".
It also says:“TypeError: unknown: Duplicate declaration “args””.
How could I improve this and what is wrong?:
const sum = (function() {
"use strict";
return function sum(a, b, ...args) {
const args = [a, b, ...args];
return args.reduce((a, b) => a + b, 0);
};
})();
console.log(sum(1, 2, 3)); // 6