Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
I am trying to write a function that takes n numbers of integer parameters and return the products of all the arguments

Here is my implementation

function multiplyAll(a, b, c){
    return a*b*c
}

This is working, but imagine we have 10 arguments, or in a case whereby we don't even know the number of arguments that will be supplied? this is exactly what I want to achieve. Thanks

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

A simple and "clean" way to do it is by using an array as parameter of the function. Like so :

function foo(args) {
  let res = 1;
  for(let i = 0; i < args.length; i++){
    res = res * args[i];
  }
  return res;
}
console.log(foo([2,3,4]))

about 4 years ago · Juan Pablo Isaza Report

0

You can use arguments like:

function argumentsFunction(a,b,c,d){
  console.log(arguments); // Object of arguments
}
argumentsFunction(1,2,3,4)

Reference:

  • arguments
about 4 years ago · Juan Pablo Isaza Report

0

In ES6 you can now use the spread operator in function parameters. You can use the following code to achieve your goal

function add(...numbers) {
  let total = 0;
  for (const number of numbers) { 
    total += number;
   }
  return total;
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!