Created
December 10, 2015 15:35
-
-
Save anonymous/3ee29c0ef7be261bba01 to your computer and use it in GitHub Desktop.
http://www.freecodecamp.com/tylerl-uxai 's solution for Bonfire: Roman Numeral Converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Bonfire: Roman Numeral Converter | |
// Author: @tylerl-uxai | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-roman-numeral-converter | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function convert(num) { | |
var romanNumerals = '', | |
decimals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1], | |
numerals = ['M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']; | |
for (var i= 0; i < decimals.length; i++){ | |
while ( num >= decimals[i] ) { | |
romanNumerals += numerals[i]; | |
num -= decimals[i]; | |
} | |
} | |
return romanNumerals; | |
} | |
convert(36); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment