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

Лопатин Николай #139

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7aa9590
первое решение
LopatinNikolai Oct 12, 2016
eb021d8
второе
LopatinNikolai Oct 12, 2016
153a6cd
№3
LopatinNikolai Oct 12, 2016
edafab9
№4
LopatinNikolai Oct 12, 2016
f9d9d0a
№5
LopatinNikolai Oct 12, 2016
2bacbcf
№6
LopatinNikolai Oct 12, 2016
f1e7218
№7
LopatinNikolai Oct 12, 2016
aaedb08
№8
LopatinNikolai Oct 12, 2016
df5e91f
№9
LopatinNikolai Oct 12, 2016
68407e8
№9
LopatinNikolai Oct 12, 2016
5256bd7
№10
LopatinNikolai Oct 12, 2016
818adfc
№11
LopatinNikolai Oct 12, 2016
b1392b8
№11
LopatinNikolai Oct 12, 2016
706347c
№12
LopatinNikolai Oct 12, 2016
cfef813
№13
LopatinNikolai Oct 12, 2016
6afa5f3
№14
LopatinNikolai Oct 12, 2016
d84cedd
№15
LopatinNikolai Oct 12, 2016
be4daf4
№16
LopatinNikolai Oct 12, 2016
89e1ce9
№17
LopatinNikolai Oct 12, 2016
e985a04
№18
LopatinNikolai Oct 12, 2016
e69bbe5
№19
LopatinNikolai Oct 12, 2016
7ec5d98
№19
LopatinNikolai Oct 12, 2016
437c734
№20
LopatinNikolai Oct 12, 2016
e774389
№21
LopatinNikolai Oct 12, 2016
bae681a
№22
LopatinNikolai Oct 12, 2016
52f1fc1
№23
LopatinNikolai Oct 12, 2016
f9f7b86
№25
LopatinNikolai Oct 12, 2016
52069bc
№26
LopatinNikolai Oct 12, 2016
bd7eb6d
№27
LopatinNikolai Oct 12, 2016
d7b9646
№28
LopatinNikolai Oct 12, 2016
098c296
№29
LopatinNikolai Oct 12, 2016
cb6743a
№30
LopatinNikolai Oct 12, 2016
c83e8f2
JSGO
LopatinNikolai Oct 12, 2016
8b42cbd
GO
LopatinNikolai Oct 12, 2016
bef999e
GO1
LopatinNikolai Oct 12, 2016
7064959
GG
LopatinNikolai Oct 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 81 additions & 2 deletions roman-time.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,91 @@
'use strict';
var cifri = ['N', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'];
var cifrii = ['N', 'X', 'XX', 'XXX', 'XL', 'L'];
var hours;
var minutes;

/**
* @param {String} time – время в формате HH:MM (например, 09:05)
* @returns {String} – время римскими цифрами (IX:V)
*/
function roman(time) {
var timeSplit = time.split(':');
var a = timeSplit[0].split('');
a[0] = parseInt(a[0], 10);
a[1] = parseInt(a[1], 10);
if (a[0] === 0 && a[1] === 0) {
hours = cifri[0];
}
if (a[0] === 0 && a[1] !== 0) {
hours = cifri[a[1]];
}
if (a[0] !== 0 && a[1] !== 0) {
hours = cifrii[(a[0])] + cifri[a[1]];
}
if (a[0] !== 0 && a[1] === 0) {
hours = cifrii[a[0]];
}

return hours;
}
function roman1(time) {
var timeSplit = time.split(':');
var b = timeSplit[1].split('');

b[0] = parseInt(b[0], 10);
b[1] = parseInt(b[1], 10);
if (b[0] === 0 && b[1] === 0) {
minutes = cifri[0];
}
if (b[0] === 0 && b[1] !== 0) {
minutes = cifri[b[1]];
}
if (b[0] !== 0 && b[1] !== 0) {
minutes = cifrii[(b[0])] + cifri[b[1]];
}
if (b[0] !== 0 && b[1] === 0) {
minutes = cifrii[b[0]];
}

return minutes;
}
function romanTime1(time) {
var timeSplit = time.split(':');
var a = timeSplit[0].split('');
a[0] = parseInt(a[0], 10);
a[1] = parseInt(a[1], 10);
if (isNaN(a[0]) || isNaN(a[1])) {
throw new TypeError();
}
if (timeSplit[0] > 23 || timeSplit[0] < 0 || isNaN(timeSplit[0])) {
throw new TypeError();
}

return (1);
}
function romanTime2(time) {
var timeSplit = time.split(':');
var b = timeSplit[1].split('');
b[0] = parseInt(b[0], 10);
b[1] = parseInt(b[1], 10);
if (isNaN(b[0]) || isNaN(b[1])) {
throw new TypeError();
}
if (timeSplit[0].length !== 2 || timeSplit[1].length !== 2) {
throw new TypeError();
}

return (1);
}
function romanTime(time) {
// Немного авторского кода и замечательной магии
return time;
var timeSplit = time.split(':');
romanTime1(time);
romanTime2(time);
if (timeSplit[1] > 59 || timeSplit[1] < 0 || isNaN(timeSplit[1])) {
throw new TypeError();
}

return (roman(time) + ':' + roman1(time));
}

module.exports = romanTime;