This commit is contained in:
eslopfer 2024-09-19 09:40:14 +03:00 committed by GitHub
commit f8f5b8c9e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 49 additions and 49 deletions

View File

@ -100,52 +100,52 @@ tests.push(async ({ eq, ctx }) => {
}) })
tests.push(async ({ eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'beer' } // test when vips answer { drink: 'iced-tea' }
// should create a list with 6-packs-beers and potatoes // should create a list with iced-tea-bottles and potatoes
const answers = [ const answers = [
{ answer: 'no', drink: 'beer' }, { answer: 'no', drink: 'beer' },
...ctx.createAnswers(1, { answer: 'yes', drink: 'beer' }), ...ctx.createAnswers(1, { answer: 'yes', drink: 'iced-tea' }),
] ]
await ctx.setAnswersIn({ dir: 'guests', answers }) await ctx.setAnswersIn({ dir: 'guests', answers })
const { data } = await ctx.run('guests', 'happy-beer-list.json') const { data } = await ctx.run('guests', 'happy-iced-tea-list.json')
return eq(data, { potatoes: 1, '6-packs-beers': 1 }) return eq(data, { potatoes: 1, 'iced-tea-bottles': 1 })
}) })
tests.push(async ({ eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'beer' } // test when vips answer { drink: 'iced-tea' }
// should create a list with 6-packs-beers and potatoes // should create a list with iced-tea-bottles and potatoes
const answers = [ const answers = [
{ answer: 'no', drink: 'beer' }, { answer: 'no', drink: 'iced-tea' },
...ctx.createAnswers(6, { answer: 'yes', drink: 'beer' }), ...ctx.createAnswers(6, { answer: 'yes', drink: 'iced-tea' }),
] ]
await ctx.setAnswersIn({ dir: 'guests', answers }) await ctx.setAnswersIn({ dir: 'guests', answers })
const { data } = await ctx.run('guests', 'happy-beer-pack-list.json') const { data } = await ctx.run('guests', 'happy-iced-tea-bottles-list.json')
return eq(data, { potatoes: 6, '6-packs-beers': 1 }) return eq(data, { potatoes: 6, 'iced-tea-bottles': 1 })
}) })
tests.push(async ({ eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'wine' } // test when vips answer { drink: 'sparkling-water' }
// should create a list with wine-bottles and potatoes // should create a list with sparkling-water-bottles and potatoes
const answers = [ const answers = [
...ctx.createAnswers(3, { answer: 'no', drink: 'wine' }), ...ctx.createAnswers(3, { answer: 'no', drink: 'sparkling-water' }),
...ctx.createAnswers(5, { answer: 'yes', drink: 'wine' }), ...ctx.createAnswers(5, { answer: 'yes', drink: 'sparkling-water' }),
] ]
await ctx.setAnswersIn({ dir: 'guests', answers }) await ctx.setAnswersIn({ dir: 'guests', answers })
const { data } = await ctx.run('guests', 'happy-wine-list.json') const { data } = await ctx.run('guests', 'happy-sparkling-water-list.json')
return eq(data, { potatoes: 5, 'wine-bottles': 2 }) return eq(data, { potatoes: 5, 'sparkling-water-bottles': 2 })
}) })
tests.push(async ({ eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
// test when vips answer { drink: 'wine' } // test when vips answer { drink: 'sparkling-water' }
// should create a list with wine-bottles and potatoes // should create a list with sparkling-water-bottles and potatoes
const answers = ctx.createAnswers(8, { answer: 'yes', drink: 'wine' }) const answers = ctx.createAnswers(8, { answer: 'yes', drink: 'sparkling-water' })
await ctx.setAnswersIn({ dir: 'guests', answers }) await ctx.setAnswersIn({ dir: 'guests', answers })
const { data } = await ctx.run('guests', 'happy-wine-bottle-list.json') const { data } = await ctx.run('guests', 'happy-sparkling-water-bottles-list.json')
return eq(data, { potatoes: 8, 'wine-bottles': 2 }) return eq(data, { potatoes: 8, 'sparkling-water-bottles': 2 })
}) })
tests.push(async ({ eq, ctx }) => { tests.push(async ({ eq, ctx }) => {
@ -365,12 +365,12 @@ tests.push(async ({ eq, ctx }) => {
}), }),
...ctx.createAnswers(6, { answer: 'yes', food: 'vegan', drink: 'water' }), ...ctx.createAnswers(6, { answer: 'yes', food: 'vegan', drink: 'water' }),
...ctx.createAnswers(2, { answer: 'yes', food: 'veggie', drink: 'water' }), ...ctx.createAnswers(2, { answer: 'yes', food: 'veggie', drink: 'water' }),
...ctx.createAnswers(3, { answer: 'yes', food: 'veggie', drink: 'beer' }), ...ctx.createAnswers(3, { answer: 'yes', food: 'veggie', drink: 'iced-tea' }),
...ctx.createAnswers(11, { answer: 'yes', food: 'fish', drink: 'wine' }), ...ctx.createAnswers(11, { answer: 'yes', food: 'fish', drink: 'sparkling-water' }),
...ctx.createAnswers(4, { ...ctx.createAnswers(4, {
answer: 'yes', answer: 'yes',
food: 'everything', food: 'everything',
drink: 'beer', drink: 'iced-tea',
}), }),
] ]
await ctx.setAnswersIn({ dir: 'guests', answers }) await ctx.setAnswersIn({ dir: 'guests', answers })
@ -388,8 +388,8 @@ tests.push(async ({ eq, ctx }) => {
sardines: 11, sardines: 11,
burgers: 2, burgers: 2,
kebabs: 4, kebabs: 4,
'6-packs-beers': 2, 'iced-tea-bottles': 2,
'wine-bottles': 3, 'sparkling-water-bottles': 3,
'water-bottles': 2, 'water-bottles': 2,
'soft-bottles': 1, 'soft-bottles': 1,
}) })

View File

@ -8,16 +8,16 @@
"code": "equal(shaker.length, 3)" "code": "equal(shaker.length, 3)"
}, },
{ {
"description": "shaker can make a cocktail.", "description": "shaker can make a skinny milkshake.",
"code": "equal(shaker(1, 'strawberry', true), '1 strawberry cocktail')" "code": "equal(shaker(1, 'strawberry', true), '1 skinny strawberry milkshake')"
}, },
{ {
"description": "shaker can make a milkshake.", "description": "shaker can make a milkshake.",
"code": "equal(shaker(1, 'strawberry', false), '1 strawberry milkshake')" "code": "equal(shaker(1, 'strawberry', false), '1 strawberry milkshake')"
}, },
{ {
"description": "shaker can make multiple cocktails.", "description": "shaker can make multiple skinny milkshakes.",
"code": "equal(shaker(7, 'banana', true), '7 banana cocktails')" "code": "equal(shaker(7, 'banana', true), '7 skinny banana milkshakes')"
}, },
{ {
"description": "shaker can make multiple milkshakes.", "description": "shaker can make multiple milkshakes.",
@ -25,6 +25,6 @@
}, },
{ {
"description": "shaker is shakin it right.", "description": "shaker is shakin it right.",
"code": "equal(shaker(1, 'vanilla', true), '1 vanilla cocktail')\nequal(shaker(1, 'mango', true), '1 mango cocktail')\nequal(shaker(2, 'banana', true), '2 banana cocktails')\nequal(shaker(2, 'chocolate', false), '2 chocolate milkshakes')\nequal(shaker(2, 'vanilla', false), '2 vanilla milkshakes')\nequal(shaker(2, 'strawberry', false), '2 strawberry milkshakes')" "code": "equal(shaker(1, 'vanilla', true), '1 skinny vanilla milkshake')\nequal(shaker(1, 'mango', true), '1 skinny mango milkshake')\nequal(shaker(2, 'banana', true), '2 skinny banana milkshakes')\nequal(shaker(2, 'chocolate', false), '2 chocolate milkshakes')\nequal(shaker(2, 'vanilla', false), '2 vanilla milkshakes')\nequal(shaker(2, 'strawberry', false), '2 strawberry milkshakes')"
} }
] ]

View File

@ -7,21 +7,21 @@
As you're smart, you asked every guest of the party to precise in their answer As you're smart, you asked every guest of the party to precise in their answer
the kind of drink they would enjoy and the kind of food they would die for. the kind of drink they would enjoy and the kind of food they would die for.
Create a `happiness-manager.mjs` script that sort, who wants to drink what and Create a `happiness-manager.mjs` script that sorts, who wants to drink what and
who wants to eat what and integrate that in your barbecue's shopping list! who wants to eat what and integrate that in your barbecue's shopping list!
> note that you must only consider **vips** guests, those that answerd `'yes'` > note that you must only consider as **VIP** guests, those that answered `'yes'`
The script must: The script must:
- Take a directory as first argument (the `guest` directory) - Take a directory as first argument (the `guest` directory)
- Take a file `.json` as second argument: - Take a file `.json` as second argument:
- If the file already exists, it will add the informations to it. If some elements already exist in the original file, it will be replaced by new values. - If the file already exists, it will add the information to it. If some elements already exist in the original file, it will be replaced by new values.
- If it doesn't, the script must handle the creation of the file. - If it doesn't, the script must handle the creation of the file.
- Handle case when no one answered yes to the invitation: - Handle the case when no one answered yes to the invitation:
- `No one is coming.` has to appear in console. - `No one is coming.` has to appear in the console.
- No file is updated/created. - No file is updated/created.
- Handle cases when answers contains no "food" information, or no "drink" - Handle cases when answers contain no "food" information, or no "drink"
information information
- Handle cases when no one has chosen a category (for example: no one chose to - Handle cases when no one has chosen a category (for example: no one chose to
drink softs). This category should not appear in the final list. drink softs). This category should not appear in the final list.
@ -29,24 +29,24 @@ The script must:
You have to handle the info like this: You have to handle the info like this:
- Drinks: - Drinks:
- Beers: 1 pack / 6 vips (rounded up). Expected key: `6-packs-beers`. - Iced tea: 1 pack / 6 VIPs (rounded up). Expected key: `iced-tea-bottles`.
- Water, wine, softs: 1 bottle / 4 vips in each category (rounded up). - Water, sparkling water, softs: 1 bottle / 4 VIPs in each category (rounded up).
Expected keys: `wine-bottles`, `water-bottles`, `soft-bottles`. Expected keys: `sparkling-water-bottles`, `water-bottles`, `soft-bottles`.
- Food: - Food:
- Veggies and vegans: 1 eggplant, 1 courgette, 3 mushrooms and 1 hummus / 3 - Veggies and vegans: 1 eggplant, 1 courgette, 3 mushrooms and 1 hummus / 3
vips in these categories put together. Expected keys: `eggplants`, VIPs in these categories put together. Expected keys: `eggplants`,
`mushrooms`, `hummus`, `courgettes`. `mushrooms`, `hummus`, `courgettes`.
- Carnivores: 1 burger per person. Expected key: `burgers`. - Carnivores: 1 burger per person. Expected key: `burgers`.
- Fish lovers: 1 sardine per person. Expected key: `sardines`. - Fish lovers: 1 sardine per person. Expected key: `sardines`.
- Omnivores: 1 chicken+shrimps+pepper kebab / person. Expected key: `kebabs`. - Omnivores: 1 chicken+shrimps+pepper kebab / person. Expected key: `kebabs`.
- Bonus: you'll add 1 potatoe per person (all categories put together). - Bonus: you'll add 1 potato per person (all categories put together).
Expected key: `potatoes`. Expected key: `potatoes`.
The infos have to be formated like this in the `.json` file: The info has to be formated like this in the `.json` file:
```js ```js
{ {
"key": 1 // according to actual number associated to the elem "key": 1 // according to actual number associated to the element
} }
``` ```

View File

@ -27,24 +27,24 @@ the string `happy` or not. The possibilities are becoming limitless...
### Instructions ### Instructions
As Rick's robot, you are continuing your training to add yourself new ... skills As Rick's robot, you are continuing your training to add yourself new ... skills
(I could have said funtions). You want now to become a robot bartender. (I could have said functions). You want now to become a robot barista.
Define the function `shaker` which will take as arguments: Define the function `shaker` which will take as arguments:
- `quantity`, which will be variable of type `Number` - `quantity`, which will be variable of type `Number`
- `fruit`, which will be a `String` - `fruit`, which will be a `String`
- `alcohol`, which will be a `Boolean` - `diet`, which will be a `Boolean`
`shaker` must return a `String`. Look at the examples below to understand how `shaker` must return a `String`. Look at the examples below to understand how
`shaker` must mix its ingredients: `shaker` must mix its ingredients:
```js ```js
console.log(shaker(1, 'strawberry', true)) console.log(shaker(1, 'strawberry', true))
//'1 strawberry cocktail' //'1 skinny strawberry milkshake'
console.log(shaker(2, 'chocolate', false)) console.log(shaker(2, 'chocolate', false))
//'2 chocolate milkshakes' //'2 chocolate milkshakes'
console.log(shaker(2, 'strawberry', true)) console.log(shaker(2, 'strawberry', true))
//'2 strawberry cocktails' //'2 skinny strawberry milkshakes'
console.log(shaker(1, 'chocolate', false)) console.log(shaker(1, 'chocolate', false))
//'1 chocolate milkshake' //'1 chocolate milkshake'
``` ```