<commit_before>var mappings = [
	{ number: 1000, numeral: "M" },
	{ number: 500, numeral: "D" },
	{ number: 100, numeral: "C" },
	{ number: 50, numeral: "L" },
	{ number: 10, numeral: "X" },
	{ number: 5, numeral: "V" },
	{ number: 1, numeral: "I" }
];

var mappingsByNumber = {};
var mappingsByNumeral = {};

var RomanNumeralMapper = function() {
	
};

RomanNumeralMapper.prototype.fromDecimal = function(number) {
	var numerals = "";

	for(var i = 0; i < mappings.length; i++) {
		var mapping = mappings[i];
		var numeralCount = 0;
		while(true) {
			if(numeralCount >= 3 || number < mapping.number) {
				break;
			}
			numerals += mapping.numeral;
			number -= mapping.number;
			numeralCount += 1;
		}

		if(mapping.number.toString().charAt(0) === "1" && number >= (mapping.number * 9 / 10)) {
			var oneTenthMapping = mappingsByNumber[mapping.number/10];
			if(oneTenthMapping) {
				numerals += oneTenthMapping.numeral + mapping.numeral;
				number -= mapping.number - oneTenthMapping.number;
			}
		} else if(number >= (mapping.number * 4 / 5)) {
			var oneFifthMapping = mappingsByNumber[mapping.number/5];
			if(oneFifthMapping) {
				numerals += oneFifthMapping.numeral + mapping.numeral;
				number -= mapping.number - oneFifthMapping.number;
			}
		}
	}
	
	return numerals;
};

RomanNumeralMapper.prototype.toDecimal = function(numerals) {
	var result = 0;

	for(var i = 0; i < numerals.length; i++) {
		if(numeralsStr.charAt(i) === "I") {
			result++;
		}
	}

	return result;
};

(function populateMappingHashes() {
	for(var i = 0; i < mappings.length; i++) {
		var mapping = mappings[i];
		mappingsByNumber[mapping.number] = mapping;
		mappingsByNumeral[mapping.numeral] = mapping;
	}
}());

module.exports = RomanNumeralMapper;
<commit_msg>Refactor RomanNumeralMapper fromDecimal method<commit_after>var mappings = [
	{ number: 1000, numeral: "M" },
	{ number: 500, numeral: "D" },
	{ number: 100, numeral: "C" },
	{ number: 50, numeral: "L" },
	{ number: 10, numeral: "X" },
	{ number: 5, numeral: "V" },
	{ number: 1, numeral: "I" }
];

var mappingsByNumber = {};
var mappingsByNumeral = {};

var RomanNumeralMapper = function() {
	this._numerals = "";
	this._number = 0;
};

RomanNumeralMapper.prototype.fromDecimal = function(number) {
	this._number = number;
	this._numerals = "";

	for(var i = 0; i < mappings.length; i++) {
		var numeralMapping = mappings[i];
		appendAdditiveNumerals.call(this, numeralMapping);
		appendNumeralsRequiringSubtraction.call(this, numeralMapping);
	}
	
	return this._numerals;
};

RomanNumeralMapper.prototype.toDecimal = function(numerals) {
	var result = 0;

	for(var i = 0; i < numerals.length; i++) {
		if(numeralsStr.charAt(i) === "I") {
			result++;
		}
	}

	return result;
};

function appendAdditiveNumerals(numeralMapping) {
	var MAX_ADDITIVE_NUMERAL_COUNT = 3;
	var numeralCount = 0;
	while(numeralCount < MAX_ADDITIVE_NUMERAL_COUNT && this._number >= numeralMapping.number) {
		this._numerals += numeralMapping.numeral;
		this._number -= numeralMapping.number;
		numeralCount += 1;
	}
}

function appendNumeralsRequiringSubtraction(numeralMapping) {
	appendNumeralsWithOneTenthSubtraction.call(this, numeralMapping);
	appendNumeralsWithOneFifthSubtraction.call(this, numeralMapping);
}

function appendNumeralsWithOneTenthSubtraction(numeralMapping) {
	if(this._number >= (numeralMapping.number * 9 / 10) && isNumberPowerOfTen(numeralMapping.number)) {
		var oneTenthMapping = mappingsByNumber[numeralMapping.number/10];
		if(oneTenthMapping) {
			this._numerals += oneTenthMapping.numeral + numeralMapping.numeral;
			this._number -= numeralMapping.number - oneTenthMapping.number;
		}
	}
}

function appendNumeralsWithOneFifthSubtraction(numeralMapping) {
	if(this._number >= (numeralMapping.number * 4 / 5)) {
		var oneFifthMapping = mappingsByNumber[numeralMapping.number/5];
		if(oneFifthMapping) {
			this._numerals += oneFifthMapping.numeral + numeralMapping.numeral;
			this._number -= numeralMapping.number - oneFifthMapping.number;
		}
	}
}

function isNumberPowerOfTen(number) {
	while(number > 1) {
		number = number / 10;
		if(number === 1) {
			return true;
		}
	}
	return false;
}

(function populateMappingHashes() {
	for(var i = 0; i < mappings.length; i++) {
		var mapping = mappings[i];
		mappingsByNumber[mapping.number] = mapping;
		mappingsByNumeral[mapping.numeral] = mapping;
	}
}());

module.exports = RomanNumeralMapper;

{'fraction_non_alphanumeric': 0.14486510995239174, 'fraction_numerical': 0.015642711403309906, 'mean_word_length': 4.426814268142682, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '952017', 'n_tokens_mistral': 1747, 'n_tokens_neox': 1535, 'n_words': 297}