if I have:
function foo(number, ...args) {
//foo to add args to sum
}
and I want a caller to be able to call foo like:
foo(10, 1, 2, 3); // 16
or:
foo(10, [1, 2, 3]); //16
The question is how to implement this. Can I do this:
function foo(number, ...args) {
let toAddArr = Array.isArray(args[0]) ? args[0] : args;
for (let toAdd of toAddArr) {
number = number + toAdd;
}
return number;
}