Ad
Fundamentals

Write a function add that uses rest parameters to sum all the numbers passed as arguments. The function should be able to handle any number of numerical inputs and return their total sum.

Examples:

add(1, 1); // returns 2
add(2, 3); // returns 5
add(-1, 1); // returns 0
add(-1, -1); // returns -2
add(1, 2, 3, 4); // returns 10
add(1, 0, -1); // returns 0

Constraints:

  • The function should only accept numbers as arguments.
  • You must use rest parameters (...) to handle the input arguments.
function add() { // Your arguments in brackets
// Your code here
}