Created
May 6, 2020 07:55
-
-
Save nikita-rudenko/dad7bd14dd1a2328b2c859d0c392d8a9 to your computer and use it in GitHub Desktop.
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 cuisinesTemplate = { | |
| american: [], | |
| italian: [], | |
| french: [] | |
| } | |
| function serveBuffet(dishes) { | |
| const buffet = dishes.reduce((acc, dish) => { | |
| const cuisine = dish.cuisine.toLowerCase(); | |
| if (acc[cuisine]) acc[cuisine].push(dish); | |
| else acc[cuisine] = [dish]; | |
| return acc; | |
| }, {...cuisinesTemplate}); | |
| return buffet; | |
| } | |
| const dishes = [ | |
| { | |
| cuisine: "American", | |
| name: "Burger", | |
| }, | |
| { | |
| cuisine: "Italian", | |
| name: "Pizza", | |
| }, | |
| { | |
| cuisine: "French", | |
| name: "Baguette", | |
| }, | |
| { | |
| cuisine: "Italian", | |
| name: "Spaghetti", | |
| }, | |
| { | |
| cuisine: "French", | |
| name: "Ratatouille", | |
| } | |
| ] | |
| serveBuffet(dishes); | |
| serveBuffet(dishes); | |
| serveBuffet(dishes); | |
| console.log(cuisinesTemplate); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment