Answers for "javascript take any number of arguments"

1

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
Posted by: Guest on June-02-2021

Code answers related to "javascript take any number of arguments"

Code answers related to "Javascript"

Browse Popular Code Answers by Language