function add() {
var values = Array.prototype.splice.call(arguments, [0]),
total = 0;
for (var value of values) {
total += value
}
return total;
}
sum(1, 2, 3, 4); // => 10
//-------- The same with spread operator ----------//
function add(...values) {
var total = 0;
for (var value of values) {
total += value
}
return total;
}
var list = [1, 2, 3];
var toAdd = [4, 5, 6];
list.push(...toAdd);
console.log(list);