From 31440cb95edee084900531eb64199c1d6a386fca Mon Sep 17 00:00:00 2001 From: YaronovaAlyona Date: Wed, 19 Oct 2016 03:09:28 +0600 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D1=80=D0=B5=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roman-time.js | 99 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 97 insertions(+), 2 deletions(-) diff --git a/roman-time.js b/roman-time.js index f66353e..4d81675 100644 --- a/roman-time.js +++ b/roman-time.js @@ -4,9 +4,104 @@ * @param {String} time – время в формате HH:MM (например, 09:05) * @returns {String} – время римскими цифрами (IX:V) */ +function checkIsValid(time) { + if (time == null || time == undefined || time.length < 5){ + throw new TypeError('Ошибка, неверный тип данных!', 'roman-time.js'); + } +} + +function getHours(hour) { + switch (hour){ + case 0: + return 'N'; + case 1: + return 'I'; + case 2: + return 'II'; + case 3: + return 'III'; + case 4: + return 'IV'; + case 5: + return 'V'; + case 6: + return 'VI'; + case 7: + return 'VII'; + case 8: + return 'VII'; + case 9: + return 'IX'; + case 10: + return 'X'; + } + +} + function romanTime(time) { - // Немного авторского кода и замечательной магии - return time; + checkIsValid(time); + + try { + var times = time.split(':'); + } + catch (e) { + throw new TypeError('Ошибка, неверный тип данных!', 'roman-time.js'); + } + + if (times.length != 2){ + throw new TypeError('Ошибка, неверный тип данных!', 'roman-time.js'); + } + + if (!(times[0] >= 0 && times[0] <= 23) && (times[1] >= 0 && times[1] <= 59)){ + throw new TypeError('Ошибка, неверный тип данных!', 'roman-time.js'); + } + + var str = ''; + + if (times[0]<= 10) { + str += getHours(times[0]) + ':'; + } + else { + var hour = times[0]; + while (hour / 10 >= 1){ + hour = hour-10; + str += 'X'; + } + if (times[0] % 10 > 0) { + str += getHours(times[0] % 10) + ':'; + } + else{ + str += ':'; + } + } + + if (times[1]<=10){ + str += getHours(times[1]); + } + else if (times[1] < 40){ + var minutes = times[1]; + while (minutes / 10 >= 1 ){ + minutes = minutes - 10; + str += 'X'; + } + if (times[1] % 10 > 0) { + str += getHours(times[1] % 10); + } + } + else if (times[1] >= 40 && times[1] < 50){ + str +='XV'; + if (times[1] % 10 > 0) { + str += getHours(times[1] % 10); + } + } + else if (times[1] >= 50){ + str +='V'; + if (times[1] % 10 > 0) { + str += getHours(times[1] % 10); + } + } + + return str; } module.exports = romanTime; From 6ed59e1f6682f16bfd54c1f31522d7e05356007a Mon Sep 17 00:00:00 2001 From: YaronovaAlyona Date: Wed, 19 Oct 2016 16:39:07 +0600 Subject: [PATCH 2/3] Update roman-time.js --- roman-time.js | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/roman-time.js b/roman-time.js index 4d81675..e162fa3 100644 --- a/roman-time.js +++ b/roman-time.js @@ -35,9 +35,36 @@ function getHours(hour) { case 10: return 'X'; } +} +function getNumber(number) { + switch (number){ + case '00': + return 'N'; + case '01': + return 'I'; + case '02': + return 'II'; + case '03': + return 'III'; + case '04': + return 'IV'; + case '05': + return 'V'; + case '06': + return 'VI'; + case '07': + return 'VII'; + case '08': + return 'VII'; + case '09': + return 'IX'; + case '10': + return 'X'; + } } + function romanTime(time) { checkIsValid(time); @@ -59,7 +86,7 @@ function romanTime(time) { var str = ''; if (times[0]<= 10) { - str += getHours(times[0]) + ':'; + str += getNumber(times[0]) + ':'; } else { var hour = times[0]; @@ -76,7 +103,7 @@ function romanTime(time) { } if (times[1]<=10){ - str += getHours(times[1]); + str += getNumber(times[1]); } else if (times[1] < 40){ var minutes = times[1]; @@ -100,7 +127,7 @@ function romanTime(time) { str += getHours(times[1] % 10); } } - + return str; } From 60bba91365b7fa1196ea9a088a2726bca1fce201 Mon Sep 17 00:00:00 2001 From: YaronovaAlyona Date: Wed, 19 Oct 2016 16:52:14 +0600 Subject: [PATCH 3/3] =?UTF-8?q?=D1=82=D1=80=D0=B5=D1=82=D0=B8=D0=B9=20?= =?UTF-8?q?=D0=B2=D0=B0=D1=80=D0=B8=D0=B0=D0=BD=D1=82=20=D1=80=D0=B5=D1=88?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roman-time.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roman-time.js b/roman-time.js index e162fa3..282df9d 100644 --- a/roman-time.js +++ b/roman-time.js @@ -5,7 +5,7 @@ * @returns {String} – время римскими цифрами (IX:V) */ function checkIsValid(time) { - if (time == null || time == undefined || time.length < 5){ + if (time === null || time === undefined || time.length < 5){ throw new TypeError('Ошибка, неверный тип данных!', 'roman-time.js'); } } @@ -75,7 +75,7 @@ function romanTime(time) { throw new TypeError('Ошибка, неверный тип данных!', 'roman-time.js'); } - if (times.length != 2){ + if (times.length !== 2){ throw new TypeError('Ошибка, неверный тип данных!', 'roman-time.js'); }