Untitled
unknown
plain_text
4 years ago
532 B
9
Indexable
/*
* Complete the 'chocolateFeast' function below.
*
* The function is expected to return an INTEGER.
* The function accepts following parameters:
* 1. INTEGER n
* 2. INTEGER c
* 3. INTEGER m
*/
function chocolateFeast(n, c, m) {
let chocolatesEaten = 0
let numWrappers = 0
while (n >= c || numWrappers >= m) {
if (numWrappers >= m) {
numWrappers -= m
} else {
n -= c
}
chocolatesEaten += 1
numWrappers += 1
}
return chocolatesEaten
}
Editor is loading...