Сообщение от Блондинка
|
function getDifference(year) {
var razn = 0;
if (year >= 300 && year <= 499) razn = 1;
else if (year >= 500 && year <= 599) razn = 2;
else if (year >= 600 && year <= 699) razn = 3;
else if (year >= 700 && year <= 899) razn = 4;
else if (year >= 900 && year <= 999) razn = 5;
else if (year >= 1000 && year <= 1099) razn = 6;
else if (year >= 1100 && year <= 1299) razn = 7;
else if (year >= 1300 && year <= 1399) razn = 8;
else if (year >= 1400 && year <= 1499) razn = 9;
else if (year >= 1500 && year <= 1699) razn = 10;
else if (year >= 1700 && year <= 1799) razn = 11;
else if (year >= 1800 && year <= 1899) razn = 12;
else if (year >= 1900 && year <= 2099) razn = 13;
else if (year >= 2100 && year <= 2199) razn = 14;
else if (year >= 2200 && year <= 2299) razn = 15;
else if (year >= 2300 && year <= 2399) razn = 16;
else if (year >= 2500 && year <= 2599) razn = 17;
else if (year >= 2600 && year <= 2699) razn = 18;
else if (year >= 2700 && year <= 2899) razn = 19;
else if (year >= 2900 && year <= 2999) razn = 20;
else if (year >= 3000 && year <= 3099) razn = 21;
else if (year >= 3100 && year <= 3299) razn = 22;
else if (year >= 3300 && year <= 3399) razn = 23;
else if (year >= 3400 && year <= 3499) razn = 24;
else if (year >= 3500 && year <= 3699) razn = 25;
else if (year >= 3700 && year <= 3799) razn = 26;
else if (year >= 3800 && year <= 3899) razn = 27;
else if (year >= 3900 && year <= 4099) razn = 28;
return razn;
}
|
Глаза режет...
Как вариант...
function test(year) {
if (year < 300) return 0;
const a = [
499, 599, 699, 899, 999, 1099, 1299, 1399, 1499, 1699, 1799,
1899, 2099, 2199, 2299, 2399, 2599, 2699, 2899, 2999, 3099,
3299, 3399, 3499, 3699, 3799, 3899, 4099
]
for (let i = 0; i < a.length; i++) {
if (year < a[ i ]) return ++i
}
return 0
}
alert(test(1000))