Skip to content

Instantly share code, notes, and snippets.

@sophiabrandt
Last active June 15, 2016 17:01
Show Gist options
  • Save sophiabrandt/ac0e7a775505018698f50060abcdf925 to your computer and use it in GitHub Desktop.
Save sophiabrandt/ac0e7a775505018698f50060abcdf925 to your computer and use it in GitHub Desktop.

Revisions

  1. sophiabrandt revised this gist Jun 15, 2016. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions fcc_roman_numeral_converter.js
    Original file line number Diff line number Diff line change
    @@ -16,9 +16,7 @@ function convertToRoman(num) {
    .set(4, 'IV')
    .set(1, 'I');


    let romanNum ='';

    // loop over the romanNumbers map and substitute the input number with the roman equivalent
    for (const [arabicLetter, romanLetter] of romanNumbers) { // destructuring the key value pairs from the map
    while (num >= arabicLetter) {
  2. sophiabrandt created this gist Jun 15, 2016.
    31 changes: 31 additions & 0 deletions fcc_roman_numeral_converter.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    function convertToRoman(num) {

    // create an ES6-map
    const romanNumbers = new Map()
    .set(1000, 'M')
    .set(900, 'CM')
    .set(500, 'D')
    .set(400, 'CD')
    .set(100, 'C')
    .set(90, 'XC')
    .set(50, 'L')
    .set(40, 'XL')
    .set(10, 'X')
    .set(9, 'IX')
    .set(5, 'V')
    .set(4, 'IV')
    .set(1, 'I');


    let romanNum ='';

    // loop over the romanNumbers map and substitute the input number with the roman equivalent
    for (const [arabicLetter, romanLetter] of romanNumbers) { // destructuring the key value pairs from the map
    while (num >= arabicLetter) {
    romanNum += romanLetter;
    num -= arabicLetter;
    }
    }
    return romanNum;

    }