Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript take any number of arguments

function sum() {
  // "arguments" is an object that can be converted to an Array
  const args = Array.from(arguments);
  return args.reduce((acc, next) => acc + next);
}

sum(1, 2);       // 3
sum(1, 2, 3);    // 6
sum(1, 2, 3, 4); // 10
 
PREVIOUS NEXT
Tagged: #javascript #number #arguments
ADD COMMENT
Topic
Name
1+7 =