Created
July 17, 2018 13:50
-
-
Save adamgiese/3bf0dd8edf00a2de4db9d699d90d8888 to your computer and use it in GitHub Desktop.
Declarative Arrays: Restaurant Reducer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const currentTime = 15; // 3:00 PM | |
const toOpenRestaurants = (openRestaurants, restaurant) => { | |
const { | |
name, | |
cuisine, | |
hours: { | |
open, | |
close, | |
} | |
} = restaurant; | |
const isOpen = currentTime > open && currentTime < close; | |
const isFood = cuisine !== 'Coffee'; | |
return isFood && isOpen ? [...openRestaurants, name] : openRestaurants; | |
}; | |
const openRestaurants = restaurants.reduce(toOpenRestaurants, []); | |
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