-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 1 - Candies.js
44 lines (32 loc) · 1.05 KB
/
Day 1 - Candies.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/* Candies
https://scrimba.com/scrim/cod1d4da69a5f4c8b9b416429
DESCRIPTION:
n children have got m pieces of candy. They want to eat as much candy as they can, but each child must eat exactly the same amount of candy as any other child.
Determine how many pieces of candy will be eatin by all the children together.
Individual pieces of candy cannot be split.
Example:
For n = 3, m = 10, the output should be candies(n,m) = 9
Each child will eat 3 pieces, so the answer is 9.
Hints: Math.floor()
*/
const candies = (children, candy) => {
const indPiecesCandy = Math.floor(candy / children)
const allCandyPiece = indPiecesCandy * children
return allCandyPiece
}
/**
* Test Suite
*/
describe('candies()', () => {
it('returns ammount of total equal candy to be eaten', () => {
// arrange
const children = 3;
const candy = 10;
// act
const result = candies(children, candy);
// log
console.log("result: ", result);
// assert
expect(result).toBe(9);
});
});