function centuryFromYear(num) {
// write code here.
if ( (num % 100) === 0 ) {
return Math.floor(num/100);
} else {
return Math.floor(num/100) + 1;
}
}
// Instructor solution, is basically the same as my solution. Different in that he has created a
const for the century where i have just wrote the code in full twice. This would be advantageous if
i have to return more than 2 cases. or had a president to have a century** variable.
// function centuryFromYear(year) {
// const century = year / 100;
// if(year % 100 === 0) {
// return century;
// }
// return Math.floor(century) + 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);
});
});