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

232
Vistas
How to get output of sum(1)(2,3)(4,5,6) without final call in currying javascript?

How to implement a function sum which will take parameters like the below and should give the output of the total sum without calling it at the end with an empty parameter call.

sum(1,2..n)(5,6…n)…(n)

example:

console.log("output should be: ", sum(1)(2,3)(4,5,6)) // output should be: 21

Note:

  1. I know we can use valueOf but that will only work if we are parsing the result in primitive value.

  2. I don't want solution for console.log(sum(1)(2,3)(4,5,6)()) // 21 as its solution I know which is:

function add(...args) {
      let a = args.reduce((a, b) => a + b, 0)
      function sum(...args){
        let b = args.reduce((a, b) => a + b, 0)
        if(b){
          return add(a+b)
        }
        return a
      }  
      return sum
}
  1. Any help/guidance or reference by which it can be achieved will be helpful.
about 4 years ago · Juan Pablo Isaza
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