"use strict"; const weekdays = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]; const openingHours = { //es6+ property assignment syntax [weekdays[3]]: { open: 12, close: 22, }, fri: { open: 11, close: 23, }, //es6+ property assignment syntax [weekdays[5]]: { open: 0, // Open 24 hours close: 24, }, }; const restaurant = { name: "Classico Italiano", address: "Via Angelo Tavanti 23, Firenze, Italy", categories: ["Italian", "Pizzeria", "Vegetarian", "Organic"], starterMenu: ["Focaccia", "Bruschetta", "Garlic Bread", "Caprese Salad"], mainMenu: ["Pizza", "Pasta", "Risotto"], //openingHours: openingHours, //es5 syntax openingHours, //es6+ syntax order: (starterIndex, mainCourseIndex) => { return [ //the scope of this keyword is global because of arrow functions restaurant.starterMenu[starterIndex], restaurant.mainMenu[mainCourseIndex], ]; }, orderDelivery: function ({ starterIndex = 2, mainCourseIndex = 0, time = new Date().getHours(), address, }) { console.log( //the scope of this keyword is lexical because of function expression `Order Recieved!! Your ${this.starterMenu[starterIndex]} and ${this.mainMenu[mainCourseIndex]} will be deleivered to ${address} at ${time}` ); }, //es6+ style of methods orderPizza(side1, side2, side3) { console.log( `Enjoy your Pizza with a complementry side of ${side1}, ${side2} and ${side3}` ); }, orderPasta: function (side1, ...otherSides) { console.log(side1, otherSides); }, }; const game = { team1: "Bayern Munich", team2: "Borrussia Dortmund", players: [ [ "Neuer", "Pavard", "Martinez", "Alaba", "Davies", "Kimmich", "Goretzka", "Coman", "Muller", "Gnarby", "Lewandowski", ], [ "Burki", "Schulz", "Hummels", "Akanji", "Hakimi", "Weigl", "Witsel", "Hazard", "Brandt", "Sancho", "Gotze", ], ], score: "4:0", scored: ["Lewandowski", "Gnarby", "Lewandowski", "Hummels"], date: "Nov 9th, 2037", odds: { team1: 1.33, x: 3.25, team2: 6.5, }, }; ///////////////////////REST PARAMETERS///////////////////////////// //SPREAD => is on the right side of the assignment operator //REST PARAMETERS => is on the left side of the assignment operator let [a, b, ...others] = [1, 2, 3, 4, 5, 6, 7, 8]; console.log(a, b, others); let [pizza, , risotto, ...otherMenuItems] = [ ...restaurant.mainMenu, ...restaurant.starterMenu, ]; console.log(pizza, risotto, ...otherMenuItems); console.log(pizza, risotto, otherMenuItems); // REST with objects let { sat: weekend, ...weekday } = restaurant.openingHours; console.log(weekend, weekday); // REST with function let aRestFunction = function (...numbers) { let sum = 0; for (let i = 0; i < numbers.length; i++) { sum += numbers[i]; } return sum; }; //Sending any number of arguments as an array console.log(aRestFunction(2, 6, 1, 1)); console.log(aRestFunction(2, 6, 1, 10, 63, 75)); console.log(aRestFunction(2, 6, 1, 1, 526, 100, 12, 63, 52, 452, 42)); //============SPREAD for aRestFunction===================// let notImportantArr = [56, 85, 96, 75, 25, 36]; console.log(aRestFunction(...notImportantArr)); //Practicle Example restaurant.orderPasta( "Prosciutto Wrapped Asparagus", "Stuffed Eggplant Parmesan", "Lemon Broccoli", "Zucchini Saute" ); restaurant.orderPasta("Zucchini Saute");