Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function getRequest(url) {
- const response = await fetch(url);
- return await response.json();
- }
- function sellsItem(shop, item) {
- return shop.products.filter(product => product.name.toLowerCase() === item.toLowerCase()).length > 0;
- }
- function getPizzerieDiLecce(shops, location, item) {
- return shops
- // Filtro per area geografica
- .filter(shop => shop.geographicArea.toLowerCase() === location.toLowerCase())
- // Filtro per vendita del singolo oggetto
- .filter(shop => sellsItem(shop, item));
- }
- async function main() {
- const shops = await getRequest("http://localhost:3000/api");
- console.log(getPizzerieDiLecce(shops, "Lecce", "Pizza"));
- }
- main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement