Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading