From 4bb0e554bb9736f89cebb14e510b85f4882c7060 Mon Sep 17 00:00:00 2001 From: Bystrova Viktoria Date: 2016年10月11日 22:57:26 +0500 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=B2=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=B2=D1=80=D0=B5=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=B2=20=D1=80?= =?UTF-8?q?=D0=B8=D0=BC=D1=81=D0=BA=D0=BE=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roman-time.js | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/roman-time.js b/roman-time.js index f66353e..d549411 100644 --- a/roman-time.js +++ b/roman-time.js @@ -5,8 +5,37 @@ * @returns {String} – время римскими цифрами (IX:V) */ function romanTime(time) { - // Немного авторского кода и замечательной магии - return time; + if (typeof time !== 'string') { + throw new TypeError('Неверное время'); + } + + var arr = time.split(':'); + var hours = parseFloat(arr[0]); + var minutes = parseFloat(arr[1]); + + if ((isNaN(hours)) || (isNaN(minutes)) || isWrongTime(hours, minutes)) { + throw new TypeError('Неверное время'); + } + + return convertToRoman(hours) + ':' + convertToRoman(minutes); +} + +function isWrongTime(hours, minutes) { + return (hours !== parseInt(hours)) || (minutes !== parseInt(minutes)) || + (hours < 0) || (hours> 23) || (minutes < 0) || (minutes> 59); +} + +function convertToRoman(number) { + if (number === 0) { + return 'N'; + } + + var tens = parseInt(number / 10); + var ones = number % 10; + var romanTens = ['', 'X', 'XX', 'XXX', 'XL', 'L']; + var romanOnes = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; + + return romanTens[tens] + romanOnes[ones]; } module.exports = romanTime; From e72a76641723dd771a0a725fe00fc8df72d74a1b Mon Sep 17 00:00:00 2001 From: Bystrova Viktoria Date: 2016年10月11日 23:10:18 +0500 Subject: [PATCH 2/3] =?UTF-8?q?=D0=97=D0=B0=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=20parseFloat=20=D0=BD=D0=B0=20Number?= 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 d549411..24981d5 100644 --- a/roman-time.js +++ b/roman-time.js @@ -10,8 +10,8 @@ function romanTime(time) { } var arr = time.split(':'); - var hours = parseFloat(arr[0]); - var minutes = parseFloat(arr[1]); + var hours = Number(arr[0]); + var minutes = Number(arr[1]); if ((isNaN(hours)) || (isNaN(minutes)) || isWrongTime(hours, minutes)) { throw new TypeError('Неверное время'); From f3e1797ef6b4e58a86727fafac89e15d08883681 Mon Sep 17 00:00:00 2001 From: Bystrova Viktoria Date: 2016年10月11日 23:41:57 +0500 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BB-=D0=B2=D0=BE=20?= =?UTF-8?q?=D0=B4=D0=B2=D0=BE=D0=B5=D1=82=D0=BE=D1=87=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roman-time.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/roman-time.js b/roman-time.js index 24981d5..091212d 100644 --- a/roman-time.js +++ b/roman-time.js @@ -10,6 +10,11 @@ function romanTime(time) { } var arr = time.split(':'); + + if (arr.length> 2) { + throw new TypeError('Неверное время'); + } + var hours = Number(arr[0]); var minutes = Number(arr[1]);

AltStyle によって変換されたページ (->オリジナル) /