Advertisement
informaticage

Pizzerie di lecce

Nov 14th, 2022
795
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. async function getRequest(url) {
  2.     const response = await fetch(url);
  3.     return await response.json();
  4. }
  5.  
  6.  
  7. function sellsItem(shop, item) {
  8.     return shop.products.filter(product => product.name.toLowerCase() === item.toLowerCase()).length > 0;
  9. }
  10.  
  11. function getPizzerieDiLecce(shops, location, item) {
  12.     return shops
  13.         // Filtro per area geografica
  14.         .filter(shop => shop.geographicArea.toLowerCase() === location.toLowerCase())
  15.         // Filtro per vendita del singolo oggetto
  16.         .filter(shop => sellsItem(shop, item));
  17. }
  18.  
  19. async function main() {
  20.     const shops = await getRequest("http://localhost:3000/api");
  21.     console.log(getPizzerieDiLecce(shops, "Lecce", "Pizza"));
  22. }
  23.  
  24. main();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement