Giter Club home page Giter Club logo

take-out-food's Introduction

Business requirement

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.

Sample for the 1st promotion

input

["ITEM0001 x 1", "ITEM0013 x 2", "ITEM0022 x 1"]

output

============= 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
===================================

Sample for the 2nd promotion

input

["ITEM0013 x 4", "ITEM0022 x 1"]

output

============= 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
===================================

Sample for no promotion

input

["ITEM0013 x 4"]

output

============= Order Detail =============
Hamburger x 4 = 24 yuan
-----------------------------------
Total:24 yuan
===================================

Practice requirement

  1. Put your code in src directory
  2. Implement function bestCharge in best-charge.js
  3. Task by drawing pipe diagram before coding
  4. Test first. Code should match your pipe diagram
  5. Clean code, proper size for function and meaningful naming

Tips

  1. functionloadAllItems() can return all items
  2. function loadPromotions() can return all promotions

Run tests

in browser

open run-specs.html in browser to see the test result

take-out-food's People

Contributors

nealseah avatar jtong avatar 313183373 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.