Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

119
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda