Skip to content

Instantly share code, notes, and snippets.

@adamgiese
Created July 17, 2018 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamgiese/2685853451c8810ed12277ddf6f757fa to your computer and use it in GitHub Desktop.
Save adamgiese/2685853451c8810ed12277ddf6f757fa to your computer and use it in GitHub Desktop.
Declarative Arrays: Chain Restaurant
const currentTime = 15; // 3:00 PM
const isOpen = ({hours: {open, close} }) =>
currentTime > open && currentTime < close;
const isFood = ({cuisine}) => cuisine !== 'Coffee';
const toName = ({name}) => name;
const openRestaurants = restaurants
.filter(isOpen)
.filter(isFood)
.map(toName)
;
console.log(openRestaurants); // ["Pizza Planet", "Bob's Burgers", "Monks Cafe"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment