function centuryFromYear(num) {
// write code here.
//Get the last two digits.
//If they're 00 then the century is whatever the first digits are
//Otherwise the century is the first digits + 1
const year = parseInt(num.toString().substr(-2));
const century = parseInt(num.toString().substr(0, num.toString().length-2));
return year === 00 ? century : 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);
});
it('returns current century for year before 1000', () => {
// arrange
const year = 969;
// act
const result = centuryFromYear(year);
// log
console.log("result 3: ", result);
// assert
expect(result).toBe(10);
});
});