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

108
Views
JavaScript array returns deepEqual

I want to return an array

function estanParaTrasplantar(alturasDePlantas) {
  let plantasMayoresA20Cm = [];
  for (let planta of alturasDePlantas) {
    if (planta.altura > 20) {
      agregar(plantasMayoresA20Cm, planta);
    }
  }
  return plantasMayoresA20Cm;
}

When I run [21, 29, 5, 20] I get this output

[] deepEqual [ 21, 29 ]

How can I return the array without the deepEqual stuff? Thanks

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

Instead of using agregar, filter out numbers greater than 20

function estanParaTrasplantar(alturasDePlantas) {
  return alturasDePlantas.filter(x => x > 20)
}

Note

for of will pick some weird array prototype values hence the weird things you're getting.

about 4 years ago · Santiago Gelvez Report

0

I edited Jorge's code and it worked. Thanks for all the help!

function estanParaTrasplantar(alturasDePlantas) {
  let plantas = alturasDePlantas;
  function maximo(lista){
    let mayores= [];
    lista.map(function(num){if (parseInt(num)>20){mayores.push(parseInt(num));}});
    return mayores;
  }
  return(maximo(plantas));
}
about 4 years ago · Santiago Gelvez 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!