Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Зверев Даниил #120

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
40 changes: 36 additions & 4 deletions roman-time.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,44 @@
'use strict';

/**
* @param {String} time – время в формате HH:MM (например, 09:05)
* @returns {String} – время римскими цифрами (IX:V)
* @param {int} element – перевод из арабской в римскую
* @returns {String} – âðåìÿ ðèìñêèìè öèôðàìè (IX:V)
*/
function concatinationTime(element) {
var onesList = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'];
var tensList = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX'];

if (element === 0) {

return 'N';
}

return tensList[Math.floor(element / 10)] + onesList[element % 10];
}

/**
* @param {String} time – âðåìÿ â ôîðìàòå HH:MM (íàïðèìåð, 09:05)
* @returns {String} – âðåìÿ ðèìñêèìè öèôðàìè (IX:V)
*/
function romanTime(time) {
// Немного авторского кода и замечательной магии
return time;
var regexp = /[0-9][0-9]:[0-9][0-9]+$/i;
if (regexp.test(time)) {

var timeList = time.split(':').map(element => parseInt(element));

var firstElement = timeList[0];
var secondElement = timeList[1];

if (firstElement >= 0 && firstElement < 24 && secondElement >= 0 && secondElement <= 60) {

return concatinationTime(firstElement) + ':' + concatinationTime(secondElement);
}
throw new TypeError();

} else {
throw new TypeError();
}
}

romanTime('24:00 ')
module.exports = romanTime;