Commit 7d9cf822 authored by Illia Baida's avatar Illia Baida

Updated Converter

parent fde42a4a
......@@ -13,6 +13,8 @@ export default class Converter {
static _maxDecimalGroupSigns = 3;
static _decimalToPropagate = null;
static _validateSign(sign) {
return sign in this.Dictionary;
}
......@@ -22,32 +24,48 @@ export default class Converter {
}
static _extractRomanSign(sign, value) {
if (value / this.Dictionary[sign] >= 1) {
const upperDictionaryValue = this.Dictionary[
this._dictionaryNames[this._dictionaryNames.indexOf(sign) - 1]
];
if (
value / this.Dictionary[sign] >= 1 &&
(value / upperDictionaryValue < 1 || upperDictionaryValue === undefined)
) {
console.log('extract', sign, value);
return value - this.Dictionary[sign];
} else {
return false;
}
}
static toRoman(decimalValue) {
let romanExpression = "";
let decimal = decimalValue;
const calculatedDictionary = this._dictionaryNames.reduce(
(dictionary, sign) => {
const extractResult = this._extractRomanSign(sign, decimal);
static _extractMultiple(sign, dictionary) {
const extractResult = this._extractRomanSign(
sign,
this._decimalToPropagate
);
if (extractResult === 0) {
dictionary[sign] = dictionary[sign] ? dictionary[sign] + 1 : 1;
return dictionary;
}
if (typeof extractResult === "number") {
decimal = extractResult;
this._decimalToPropagate = extractResult;
dictionary[sign] = dictionary[sign] ? dictionary[sign] + 1 : 1;
return this._extractMultiple(sign, dictionary);
}
return dictionary;
},
}
static toRoman(decimalValue) {
let romanExpression = "";
this._decimalToPropagate = decimalValue;
const calculatedDictionary = this._dictionaryNames.reduce(
(dictionary, sign) => this._extractMultiple(sign, dictionary),
{}
);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment