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
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.
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));
}