1
A virtual store allows its visitors to filter products by price. There is an array of product prices. A programmer has already created a function maisBaratosQue(valor, precos)
that returns an array with prices of products cheaper than the value passed as parameter. Another programmer has already created a function maisCarosQue(valor, precos)
that returns an array with prices more expensive than the value passed as parameter. It’s your turn!
Create a function precosEntre(valorMenor, valorMaior, precos)
that must use the functions maisBaratosQue
and maisCarosQue
to return the prices that are between the valorMenor
and the valorMaior
. Your function should then receive 3 parameters:
valorMenor
to represent the minimum value of the prices to be listedvalorMaior
to represent the maximum value of the prices to be listedprecos
to represent an array of product prices
It should return an array with all prices between valorMenor
and valorMaior
.
Follow the code, I’m trying but I’m not getting:
function maisBaratosQue(valor, precos) {
return precos.filter(p => p <= valor);
}
function maisCarosQue(valor, precos){
return precos.filter(p => p >= valor);
}
function precosEntre(valorMenor, valorMaior, precos){
return precos.filter(p => p <= valorMenor && p >= valorMaior);
}
What error is appearing? I tested here and the three functions seem to work well
– Heitor Quaglia
Errors: When performing its function by passing "prices Center(5, 10, [ 1,2,3,4,5,6,7,8,9,10])" should return the following array: [5, 6, 7, 8, 9, 10]. Check the return.
– user196388
James, have you ever done the tour? https://answall.com/tour Your question is very broad and doesn’t really have a problem. You can probably solve this problem by reading a bit of Javascript’s Map, Reduce and Filter documentation.
– M. Bertolazo
I’m new to javascript. Thanks
– user196388