function getCenturyFromYear(year) {
return Math.floor((year - 1) / 100) + 1;
}
const arr = [100, 101, 340, 570, 1000, 1005, 1999, 2000, 2001, 2022];
arr.forEach(function(yr) {
console.log('year ' + yr + ' is in ' + getCenturyFromYear(yr) + ' century');
});
/*
run:
year 100 is in 1 century
year 101 is in 2 century
year 340 is in 4 century
year 570 is in 6 century
year 1000 is in 10 century
year 1005 is in 11 century
year 1999 is in 20 century
year 2000 is in 20 century
year 2001 is in 21 century
year 2022 is in 21 century
*/