Hi all!
I’m completely new to programming but have spent the last few days powering through the exercises. I just finished the Roman Numeral Converter and felt very good about it since I devised the entire solution by myself. Curious to see how others would’ve gotten to the same result, I looked for alternative solutions and came across this thread:
When I saw the “Basic” and “Intermediate” solutions, I was struck with the question: How do I know whether my code is good/bad, basic/advanced after clearing the basic hurdle of having it satisfy the requirements?
For example, here’s my original code for the exercise. How can I tell if its efficient or not? Should I even worry about it at this point? Thanks!
function convertToRoman(num) {
//Setup
var patterns = ["", "A", "AA", "AAA", "AB", "B", "BA", "BAA", "BAAA", "AC", "C"];
var sets = [["I","V","X"], ["X","L","C"], ["C","D","M"], ["M","M","M"]];
var numArray = [];
var finalArray = [];
var testString = "";
//Execution
if (num > 3999) {
return "Value too large!";
}
num = num.toString();
numArray = num.split("");
numArray = numArray.reverse();
for (var i = 0; i < numArray.length; i++){
numArray[i] = patterns[numArray[i]];
}
for (var j = 0; j < numArray.length; j++){
testString = numArray[j];
testString = testString.replace(/C/g, sets[j][2]);
testString = testString.replace(/B/g, sets[j][1]);
testString = testString.replace(/A/g, sets[j][0]);
finalArray.push(testString);
}
finalArray = finalArray.reverse();
return finalArray.join("");
}