-3
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 two 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
function maisBaratosQue(valor, precos) {
return precos.filter(p => p <= valor);
}
function maisCarosQue(valor, precos){
return precos.filter(p => p >= valor);
}
function precosEntre(valorMaior, valorMenor, precos) {
precos.filter( maisBaratosQue() && maisCarosQue(), valor);
return precosEntre;
}