https://www.codewars.com/kata/5875b200d520904a04000003
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
The Story:
Bob is working as a bus driver. However, he has become extremely popular amongst the city's residents. With so many passengers wanting to get aboard his bus, he sometimes has to face the problem of not enough space left on the bus! He wants you to write a simple program telling him if he will be able to fit all the passengers.
Task Overview:
You have to write a function that accepts three parameters:
- cap is the amount of people the bus can hold excluding the driver.
- on is the number of people on the bus excluding the driver.
- wait is the number of people waiting to get on to the bus excluding the driver.
If there is enough space, return 0, and if there isn't, return the number of passengers he can't take.
Usage Examples:
cap = 10, on = 5, wait = 5 --> 0 # He can fit all 5 passengers
cap = 100, on = 60, wait = 50 --> 10 # He can't fit 10 of the 50 waiting
코드
function enough(cap, on, wait) {
return cap - on - wait >= 0 ? 0 : wait + on - cap;
}
'알고리즘 > Codewars' 카테고리의 다른 글
[Codewars] Quarter of the year (8 kyu) / JavaScript (0) | 2023.02.06 |
---|---|
[Codewars] Plural (8 kyu) / JavaScript (0) | 2023.02.05 |
[Codewars] Simple Fun #176: Reverse Letter (7 kyu) / JavaScript (0) | 2023.02.03 |
[Codewars] Count characters in your string (6 kyu) / JavaScript (0) | 2023.02.02 |
[Codewars] Parse nice int from char problem (8 kyu) / JavaScript (0) | 2023.02.01 |
댓글