Skip to content

Instantly share code, notes, and snippets.

@SPY
Last active March 21, 2018 21:16
Show Gist options
  • Save SPY/6aca1b88129888318efc2b2ec794068a to your computer and use it in GitHub Desktop.
Save SPY/6aca1b88129888318efc2b2ec794068a to your computer and use it in GitHub Desktop.
function whereToEat(except) {
const ALL_OPTIONS = [
{ name: 'Китайцы', days: [2, 3, 4, 5] },
{ name: 'Итальянцы', days: [2, 3, 4, 5] },
{ name: 'Греки', days: [1, 2, 3, 4, 5] },
{ name: 'Суши', days: [2, 3, 4, 5] },
{ name: 'Вьетнамцы', days: [2, 4, 5] },
{ name: 'Кабул', days: [5] },
{ name: 'Джерси Джо', days: [2, 3, 4, 5] },
{ name: 'Бургеры', days: [2, 3, 4, 5] },
{ name: 'Сабвей', days: [1] },
{ name: 'Гоу Фиш', days: [1] },
{ name: 'Хигума', days: [3, 4] },
{ name: 'Мексиканцы', days: [1, 2, 3, 4, 5] },
]
const options = ALL_OPTIONS.filter(opt => {
const today = new Date().getDay()
return opt.days.indexOf(today) >= 0 && (!except || except.indexOf(opt.name) < 0)
})
return options[Math.floor(options.length * Math.random())].name
}
@SPY
Copy link
Author

SPY commented Mar 20, 2018

Example of usage: whereToEat(['Суши'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment