A restaurant provides theirs' customers an mobile App that customers can order food on mobile phone. And the App will show customers the charge based on selected items, count and promotion.
There are multiple kinds of promotion, but only one promotion per order. Then it would be a question for customers, which promotion offers the best price. So in order to make it more friendly to customers , the App will automaticly choose the best price promotion for customers.
Now we need to implement function bestCharge which can take selected items and count(in specific form) as input, then return calculated receipt.
Known:
- Every item has only one uniq id
- Two kinds of promotions:
- Buy 30 save 6 yuan
- 50% discount on specified items
- There is no additional charge(e.g. delivery fee or package fee)
- If two promotions get the same price, then the first promotion is prefered.
["ITEM0001 x 1", "ITEM0013 x 2", "ITEM0022 x 1"]
============= Order Detail =============
Fried Chicken x 1 = 18 yuan
Hamburger x 2 = 12 yuan
Tomato Noodle x 1 = 8 yuan
-----------------------------------
Promotion Applied:
50% discount on specified items(Fried Chicken,Noodle),saved 13 yuan
-----------------------------------
Total:25 yuan
===================================
["ITEM0013 x 4", "ITEM0022 x 1"]
============= Order Detail =============
Hamburger x 4 = 24 yuan
Noodle x 1 = 8 yuan
-----------------------------------
Promotion Applied:
Buy 30 save 6 yuan,saved 6 yuan
-----------------------------------
Total:26 yuan
===================================
["ITEM0013 x 4"]
============= Order Detail =============
Hamburger x 4 = 24 yuan
-----------------------------------
Total:24 yuan
===================================
- Put your code in src directory
- Implement function bestCharge in best-charge.js
- Task by drawing pipe diagram before coding
- Test first. Code should match your pipe diagram
- Clean code, proper size for function and meaningful naming
- function
loadAllItems()
can return all items - function
loadPromotions()
can return all promotions
open run-specs.html
in browser to see the test result