Last active
March 21, 2018 21:16
-
-
Save SPY/6aca1b88129888318efc2b2ec794068a to your computer and use it in GitHub Desktop.
This file contains 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
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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of usage:
whereToEat(['Суши'])