From 8b8c85d86ffa4fe1da37be04c47cafcfd1fd7dae Mon Sep 17 00:00:00 2001 From: Sergey Kniga Date: Wed, 12 Oct 2016 14:40:35 +0500 Subject: [PATCH 1/7] =?UTF-8?q?=D0=A0=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roman-time.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/roman-time.js b/roman-time.js index f66353e..73c9f92 100644 --- a/roman-time.js +++ b/roman-time.js @@ -5,8 +5,34 @@ * @returns {String} – время римскими цифрами (IX:V) */ function romanTime(time) { - // Немного авторского кода и замечательной магии - return time; + var tokens = time.split(':'); + + var hours = parseInt(tokens[0], 10); + var minutes = parseInt(tokens[1], 10); + + if (isNaN(hours) || isNaN(minutes) || + hours < 0 || hours > 23 || + minutes < 0 || minutes > 60) { + throw new Error('TypeError: Неверное время'); + } + + return toRoman(hours) + ':' + toRoman(minutes); +} + +function toRoman(number) { + var ones = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; + var tens = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX']; + var zero = 'N'; + + var result = ''; + result += ones[number % 10]; + result += tens[(number / 10) % 10]; + + if (result === '') { + result = zero; + } + + return result; } module.exports = romanTime; From 977d68e8890ccfc32fb5acc49e706a5784937a64 Mon Sep 17 00:00:00 2001 From: Sergey Kniga Date: Wed, 12 Oct 2016 15:13:58 +0500 Subject: [PATCH 2/7] =?UTF-8?q?'=D0=A3=D0=BF=D1=80=D0=BE=D1=81=D1=82=D0=B8?= =?UTF-8?q?=D0=BB'=20=D1=80=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- roman-time.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/roman-time.js b/roman-time.js index 73c9f92..bf83b68 100644 --- a/roman-time.js +++ b/roman-time.js @@ -10,9 +10,13 @@ function romanTime(time) { var hours = parseInt(tokens[0], 10); var minutes = parseInt(tokens[1], 10); - if (isNaN(hours) || isNaN(minutes) || - hours < 0 || hours > 23 || - minutes < 0 || minutes > 60) { + if (isNaN(hours) || isNaN(minutes)) { + throw new Error('TypeError: Неверное время'); + } + if (hours < 0 || hours > 23) { + throw new Error('TypeError: Неверное время'); + } + if (minutes < 0 || minutes > 60) { throw new Error('TypeError: Неверное время'); } From e5a4275dd77bb4d7ae8b425e4dd02aa1dfddafae Mon Sep 17 00:00:00 2001 From: Sergey Kniga Date: Wed, 12 Oct 2016 15:29:17 +0500 Subject: [PATCH 3/7] complexety... --- roman-time.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/roman-time.js b/roman-time.js index bf83b68..496e27d 100644 --- a/roman-time.js +++ b/roman-time.js @@ -10,19 +10,21 @@ function romanTime(time) { var hours = parseInt(tokens[0], 10); var minutes = parseInt(tokens[1], 10); - if (isNaN(hours) || isNaN(minutes)) { - throw new Error('TypeError: Неверное время'); - } - if (hours < 0 || hours > 23) { - throw new Error('TypeError: Неверное время'); - } - if (minutes < 0 || minutes > 60) { + if (checkHours(hours) || checkMinutes(minutes)) { throw new Error('TypeError: Неверное время'); } return toRoman(hours) + ':' + toRoman(minutes); } +function checkHours(hours) { + return isNaN(hours) || hours < 0 || hours > 23; +} + +function checkMinutes(minutes) { + return isNaN(minutes) || minutes < 0 || minutes > 60; +} + function toRoman(number) { var ones = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; var tens = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX']; From f400da6bdbaf609e2b2ef37d9d4a860a60bd460f Mon Sep 17 00:00:00 2001 From: Sergey Kniga Date: Wed, 12 Oct 2016 15:37:49 +0500 Subject: [PATCH 4/7] complexety... --- roman-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roman-time.js b/roman-time.js index 496e27d..37a9d24 100644 --- a/roman-time.js +++ b/roman-time.js @@ -11,7 +11,7 @@ function romanTime(time) { var minutes = parseInt(tokens[1], 10); if (checkHours(hours) || checkMinutes(minutes)) { - throw new Error('TypeError: Неверное время'); + throw new TypeError('Неверное время'); } return toRoman(hours) + ':' + toRoman(minutes); From 6dee37bc34e7420e5133da7c67c411e04e5a7329 Mon Sep 17 00:00:00 2001 From: Sergey Kniga Date: Wed, 12 Oct 2016 15:43:59 +0500 Subject: [PATCH 5/7] [a/b%c] --- roman-time.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roman-time.js b/roman-time.js index 37a9d24..826ed72 100644 --- a/roman-time.js +++ b/roman-time.js @@ -32,7 +32,7 @@ function toRoman(number) { var result = ''; result += ones[number % 10]; - result += tens[(number / 10) % 10]; + result += tens[Math.floor(number / 10) % 10]; if (result === '') { result = zero; From 31887d4f814b597c04b8e9e1308498e2217130f8 Mon Sep 17 00:00:00 2001 From: Sergey Kniga Date: Wed, 12 Oct 2016 15:45:58 +0500 Subject: [PATCH 6/7] [a/b%c] --- roman-time.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/roman-time.js b/roman-time.js index 826ed72..9f3dbea 100644 --- a/roman-time.js +++ b/roman-time.js @@ -31,8 +31,8 @@ function toRoman(number) { var zero = 'N'; var result = ''; - result += ones[number % 10]; - result += tens[Math.floor(number / 10) % 10]; + result = result + ones[number % 10]; + result = result + tens[Math.floor(number / 10) % 10]; if (result === '') { result = zero; From ebfd9a22583d09f1531ac3a18054e980a3034d55 Mon Sep 17 00:00:00 2001 From: Sergey Kniga Date: Wed, 12 Oct 2016 15:55:02 +0500 Subject: [PATCH 7/7] [a/b%c] --- roman-time.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/roman-time.js b/roman-time.js index 9f3dbea..6b9c63d 100644 --- a/roman-time.js +++ b/roman-time.js @@ -27,12 +27,12 @@ function checkMinutes(minutes) { function toRoman(number) { var ones = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX']; - var tens = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX']; + var tens = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX']; var zero = 'N'; var result = ''; - result = result + ones[number % 10]; - result = result + tens[Math.floor(number / 10) % 10]; + result += ones[number % 10]; + result += tens[Math.floor(number / 10) % 10]; if (result === '') { result = zero;