Skip to content

Instantly share code, notes, and snippets.

@thomascothran
Last active April 29, 2017 22:18
Show Gist options
  • Save thomascothran/51aa8fa9ac3d99aa00c44c37b31b18b2 to your computer and use it in GitHub Desktop.
Save thomascothran/51aa8fa9ac3d99aa00c44c37b31b18b2 to your computer and use it in GitHub Desktop.

Revisions

  1. Thomas revised this gist Apr 29, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion arabify2.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    const nums = {I: 1, V: 5, X: 10, L: 50, C: 100, M: 1000};

    const arabify2 = (romNum, sum=0) => {
    [fst, snd, rest] = [romNum[0], romNum[1], romNum.slice(2)];
    const [fst, snd, rest] = [romNum[0], romNum[1], romNum.slice(2)];
    if (!snd) {return nums[fst] ? nums[fst] + sum : sum;}
    else if (nums[snd] > nums[fst]) {
    return arabify2(rest, nums[snd] - nums[fst] + sum);
  2. Thomas created this gist Apr 29, 2017.
    9 changes: 9 additions & 0 deletions arabify2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    const nums = {I: 1, V: 5, X: 10, L: 50, C: 100, M: 1000};

    const arabify2 = (romNum, sum=0) => {
    [fst, snd, rest] = [romNum[0], romNum[1], romNum.slice(2)];
    if (!snd) {return nums[fst] ? nums[fst] + sum : sum;}
    else if (nums[snd] > nums[fst]) {
    return arabify2(rest, nums[snd] - nums[fst] + sum);
    } else {return arabify2(snd + rest, nums[fst] + sum);}
    }