Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
roman-numerals-converter
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Illia Baida
roman-numerals-converter
Commits
c758a898
Commit
c758a898
authored
Mar 30, 2020
by
Illia Baida
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated Converter
parent
7d9cf822
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
3 deletions
+59
-3
converter.js
src/helper/converter.js
+59
-3
No files found.
src/helper/converter.js
View file @
c758a898
...
...
@@ -20,7 +20,7 @@ export default class Converter {
}
static
_isSignDescribesDecimalGroup
(
sign
)
{
return
String
(
this
.
Dictionary
[
sign
]).
substring
(
0
,
1
)
=
==
"5"
;
return
String
(
this
.
Dictionary
[
sign
]).
substring
(
0
,
1
)
!
==
"5"
;
}
static
_extractRomanSign
(
sign
,
value
)
{
...
...
@@ -32,7 +32,7 @@ export default class Converter {
value
/
this
.
Dictionary
[
sign
]
>=
1
&&
(
value
/
upperDictionaryValue
<
1
||
upperDictionaryValue
===
undefined
)
)
{
console
.
log
(
'extract'
,
sign
,
value
);
console
.
log
(
"extract"
,
sign
,
value
);
return
value
-
this
.
Dictionary
[
sign
];
}
else
{
return
false
;
...
...
@@ -60,6 +60,17 @@ export default class Converter {
return
dictionary
;
}
static
_formatExpression
()
{}
static
_multiplyString
(
str
,
times
)
{
let
res
=
""
;
for
(
let
i
=
0
;
i
<
times
;
i
++
)
{
res
+=
str
;
}
return
res
;
}
static
toRoman
(
decimalValue
)
{
let
romanExpression
=
""
;
this
.
_decimalToPropagate
=
decimalValue
;
...
...
@@ -69,7 +80,52 @@ export default class Converter {
{}
);
console
.
log
(
calculatedDictionary
);
console
.
log
(
"calculatedDictionary"
,
calculatedDictionary
);
const
skippedNames
=
[];
for
(
let
index
=
0
;
index
<
this
.
_dictionaryNames
.
length
;
index
++
)
{
const
sign
=
this
.
_dictionaryNames
[
index
];
if
(
skippedNames
.
indexOf
(
sign
)
!==
-
1
){
console
.
log
(
'skipping'
,
sign
);
continue
;
}
if
(
sign
in
calculatedDictionary
)
{
if
(
this
.
_isSignDescribesDecimalGroup
(
sign
))
{
if
(
calculatedDictionary
[
sign
]
>
this
.
_maxDecimalGroupSigns
)
{
const
upperName
=
this
.
_dictionaryNames
[
index
-
1
];
const
result
=
upperName
?
`
${
sign
}${
upperName
}
`
:
this
.
_multiplyString
(
sign
,
calculatedDictionary
[
sign
]);
romanExpression
+=
result
;
}
else
{
romanExpression
+=
this
.
_multiplyString
(
sign
,
calculatedDictionary
[
sign
]
);
}
}
else
{
const
lowerName
=
this
.
_dictionaryNames
[
index
+
1
];
const
upperName
=
this
.
_dictionaryNames
[
index
-
1
];
if
(
calculatedDictionary
[
sign
]
<=
1
)
{
if
(
calculatedDictionary
[
lowerName
]
>
this
.
_maxDecimalGroupSigns
)
{
const
result
=
`
${
lowerName
}${
upperName
}
`
;
romanExpression
+=
result
;
}
else
{
romanExpression
+=
`
${
sign
}${
this
.
_multiplyString
(
lowerName
,
calculatedDictionary
[
lowerName
]
)}
`
;
// skip
skippedNames
.
push
(
lowerName
);
}
}
else
{
throw
new
Error
(
"Cannot be greater than 1"
);
}
}
}
}
return
romanExpression
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment