-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDeodorant Evaporator (7 kyu)
28 lines (20 loc) · 1.11 KB
/
Deodorant Evaporator (7 kyu)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Deodorant Evaporator (7 kyu)
// https://www.codewars.com/kata/5506b230a11c0aeab3000c1f
// Description:
// This program tests the life of an evaporator containing a gas.
// We know the content of the evaporator (content in ml), the percentage of foam or gas lost every day (evap_per_day) and the threshold (threshold) in percentage beyond which the evaporator is no longer useful. All numbers are strictly positive.
// The program reports the nth day (as an integer) on which the evaporator will be out of use.
// Example:
// evaporator(10, 10, 5) -> 29
// Note:
// Content is in fact not necessary in the body of the function "evaporator", you can use it or not use it, as you wish. Some people might prefer to reason with content, some other with percentages only. It's up to you but you must keep it as a parameter because the tests have it as an argument.
// My Solution:
function evaporator(content, evap_per_day, threshold) {
let counter = 0
let target = content * threshold / 100
while (content > target) {
content = content - (content * evap_per_day / 100)
counter++
}
return counter
}