Hello everyone, I wrote a program and I need the Roman numerals to be converted. In the code that I wrote, this issue was not resolved, I found a solution on the Internet, but still, the program does not pass tests using this method.
if (num === 0){
return romanNumerals.join("")
}
else if (num >= 1000){
romanNumerals.push("M")
num -= 1000
return convertToRoman(num)
}
else if (num >= 900){
romanNumerals.push("CM")
num -= 900
return convertToRoman(num)
}
else if (num >= 500){
romanNumerals.push("D")
num -= 500
return convertToRoman(num)
}
else if (num >= 400){
romanNumerals.push("CD")
num -= 400
return convertToRoman(num)
}
else if (num >= 100){
romanNumerals.push("C")
num -= 100
return convertToRoman(num)
}
else if (num >= 90){
romanNumerals.push("XC")
num -= 90
return convertToRoman(num)
}
else if (num >= 50){
romanNumerals.push("L")
num -= 50
return convertToRoman(num)
}
else if (num >= 40){
romanNumerals.push("XL")
num -= 40
return convertToRoman(num)
}
else if (num >= 10) {
romanNumerals.push("X")
num -= 10
return convertToRoman(num)
}
else if (num >=9){
romanNumerals.push("IX")
num -= 9
return convertToRoman(num)
}
else if (num >=5) {
romanNumerals.push("V")
num -= 5
return convertToRoman(num)
}
else if (num == 4){
romanNumerals.push("IV")
num -= 4
return convertToRoman(num)
}
else if (num >=1){
romanNumerals.push("I")
num -=1
return convertToRoman(num)
}
}
console.log(convertToRoman(900))
```Can you tell me how to fix this code so as not to break its functionality?
And another question, are there any services that do source code analysis and help with uniqueness? Thanks!