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

373
Views
Problema de Javascript realmente extraño, ¿cómo puedo solucionarlo?

Estoy haciendo una forma más "humana" de hacer matemáticas, y está funcionando bien, sin embargo, algo pasa con mi código.

Básicamente, le digo al código que sume 6 y 4 y lo genere. Me da lo que estoy esperando, un poco. Sin embargo, la parte extraña al respecto, en lugar de imprimir directamente solo '10', dice:

 [undefined, undefined, undefined, 10]

¿Cómo puedo hacer que devuelva solo '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
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!