Coding 3min : Hacker and change
Description:
Task:
John is a hacker, he always believed,"Knowledge can change the destiny".
He is ready to invade a supermarket checkout system. say concretely, his goal is the supermarket cash receipts and payments software.
The basic function of the software is:
Accept three parameters:
name
, a string, customer name
items
, an array, the price list of all the goods purchased by the customer. All elements in the array are numbers, up to two decimal places.
payment
, a number, cash paid by customer
return a number, the change returned to customer, up to two decimal places. When the cash paid by the customer is insufficient, the return is negative.
John added a rule based on this:
When the customer name is "John"
If the result >0, the decimal portion is doubled.
for example:
change("John",[1.1,2.2,3.3],10)
John bought three pieces of goods,
the total value is 1.1+2.2+3.3=6.6, payment is 10
The cashier should give John the change 3.4
But due to a "small fault", the change became 3+0.4*2=3.8
If the result <=0, return 0.
for example:
change("John",[11],10)
John bought one good=11, payment is 10, result=-1
It means John needs to give the cashier 1
But due to a "small fault", the change became 0
John doesn't need to pay the cashier
So John can save a lot of money, God bless the police will not catch him ;-)
Series:
- Bug in Apple
- Father and Son
- Jumping Dutch act
- Planting Trees
- Give me the equation
- Find the murderer
- Reading a Book
- Eat watermelon
- Special factor
- Guess the Hat
- Symmetric Sort
- Are they symmetrical?
- Max Value
- Trypophobia
- Virus in Apple
- Balance Attraction
- Remove screws I
- Remove screws II
- Regular expression compression
- Collatz Array(Split or merge)
- Tidy up the room
- Waiting for a Bus
Similar Kata:
Stats:
Created | Apr 18, 2016 |
Published | Apr 18, 2016 |
Warriors Trained | 414 |
Total Skips | 7 |
Total Code Submissions | 911 |
Total Times Completed | 193 |
JavaScript Completions | 193 |
Total Stars | 9 |
% of votes with a positive feedback rating | 92% of 66 |
Total "Very Satisfied" Votes | 58 |
Total "Somewhat Satisfied" Votes | 5 |
Total "Not Satisfied" Votes | 3 |
Total Rank Assessments | 7 |
Average Assessed Rank | 7 kyu |
Highest Assessed Rank | 7 kyu |
Lowest Assessed Rank | 8 kyu |