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

378
Vistas
Really weird Javascript issue, how can I fix it?

I am making a more "human" way to do math, and it's doing ok, however something is up with my code.

Basically, I'm telling the code to add 6 and 4 together and output it. It gives me what I'm expecting, somewhat. However the weird part about it, instead of printing straight just '10', it says:

[undefined, undefined, undefined, 10]

How can I just get it to return just '10'?

function output(func) {
  console.log(func)
}
var dl = []
const read = str => {
  return str.split(' ').map(item => {
    dl.push(item.trim())
    if (dl.length >= 4) {
      const operator = dl.find(x => x.includes("add", "sub", "mul", "div"))
      const numbers = dl.filter(x => Number(x))
      switch (operator) {
        case "add":
          return numbers.reduce((a, b) => Number(a) + Number(b));
      }
    }
  })
}
var main = read(
  `add 6 and 4`
)
output(main)

about 4 years ago · Santiago Gelvez
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