1
Ask me to do a function, which takes a parameter (array
) and return positive balances (profitably) of that month, using for
and probably a if
.
Example:
saldosDeMesesComLucro([100, 20, 0, -10, 10]);
Exit
// deve retornar [100, 20, 10].
I tried to:
function saldoDeMesesComLucro(saldos){
for(var i = 0; i < saldos.length; i++){
if(saldos[i] > 0){
return saldos;
}
}
}
But it’s not the right logic?
You can also use the
map
to return a new array the way you wantconst valoresPositivos = saldos.map(item => item > 0)
– Rubens Barbosa
Yes, but I found this way simpler for those who apparently don’t have much experience.
– G. Bittencourt