Code Monkey home page Code Monkey logo

checkout-process-workshop's Introduction

Checkout

The purpose of this challenge is to implement a supermarket checkout that calculates the total price of a number of items - to be run in a REPL like IRB. Don't worry about I/O.

Requirements

In a normal supermarket, things are identified using Stock Keeping Units, or SKUs. In our store, we'll use individual letters of the alphabet (A, B, C, and so on). Our goods are priced individually. In addition, some items are multi-priced: buy n of them, and they'll cost you y pounds.

For example, item A might cost 50 pounds individually, but this week we have a special offer:

  • buy three As and they'll cost you 130.

Our price table and offers:

+------+-------+----------------+
| Item | Price | Special offers |
+------+-------+----------------+
| A    | 50    | 3A for 130     |
| B    | 30    | 2B for 45      |
| C    | 20    |                |
| D    | 15    |                |
+------+-------+----------------+

Notes:

  • For any illegal input (non capitals) simply return -1

In order to complete the round you need to implement the following method: checkout(String) -> Integer

Where:

  • param[0] = eg. 'AAB', a String containing the SKUs of all the products in the basket
  • @return = eg. 120, an Integer representing the total checkout value of the items

Acceptance Criteria

shop.checkout('aBc') # => -1
shop.checkout('-B8x') # => -1
shop.checkout(18) # => -1
shop.checkout('AA') # => 100
shop.checkout('ABCD') # => 115
shop.checkout('AAA') # => 130
shop.checkout('AAAAAA') # => 260

Input/Output table

Input Output
shop.checkout('A') 50
shop.checkout('B') 30
shop.checkout('C') 20
shop.checkout('D') 15
shop.checkout('AA') 100
shop.checkout('CC') 40
shop.checkout('DD') 30
shop.checkout('BB') 45
shop.checkout('BBB') 75
shop.checkout('BBBB') 90
shop.checkout('BBBBB') 120
shop.checkout('BBBBBB') 135
shop.checkout('AB') 80
shop.checkout('aBc') -1
shop.checkout('-B8x') -1
shop.checkout('-') -1
shop.checkout(18) -1
shop.checkout('ABCD') 115
shop.checkout('AAA') 130
shop.checkout('AAAA') 180
shop.checkout('AAAAA') 230
shop.checkout('AAAAAA') 260
shop.checkout('AAAAAAA') 310

checkout-process-workshop's People

Contributors

davmcgregor avatar

Watchers

James Cloos avatar

Forkers

tobydawson1

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.