javascript take any number of arguments

Solutions on MaxInterview for javascript take any number of arguments by the best coders in the world

showing results for - "javascript take any number of arguments"
Henri
12 Jan 2017
1function sum() {
2  // "arguments" is an object that can be converted to an Array
3  const args = Array.from(arguments);
4  return args.reduce((acc, next) => acc + next);
5}
6
7sum(1, 2);       // 3
8sum(1, 2, 3);    // 6
9sum(1, 2, 3, 4); // 10