-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDay 4 - CenturyFromAYear.js
58 lines (43 loc) · 1.28 KB
/
Day 4 - CenturyFromAYear.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*Century From A Year
https://scrimba.com/learn/adventcalendar/note-at-0-30-co836436e940c8b0a68d55316
DESCRIPTION:
Given a year, return the century it is in.
The first century spans from the year 1 up to and including the year 100.
The second from the year 101 up to and including the year 200, etc.
Example:
For year = 1905, the output should be centuryFromyEAR(YEAR) = 20
For year = 1700, the output should be centuryFromYear(year) = 17
Hints: Math.floor()
*/
const centuryFromYear = (num) => {
let divResult = num / 100
if (num % 100 == 0) {
return divResult
}
return Math.floor(divResult) + 1
}
/**
* Test Suite
*/
describe('centuryFromYear()', () => {
it('returns current century', () => {
// arrange
const year = 1905;
// act
const result = centuryFromYear(year);
// log
console.log("result 1: ", result);
// assert
expect(result).toBe(20);
});
it('returns current century for edge case of start of century', () => {
// arrange
const year = 1700;
// act
const result = centuryFromYear(year);
// log
console.log("result 2: ", result);
// assert
expect(result).toBe(17);
});
});