Roman numerals/Decode: Difference between revisions
m
→JS Folding from the right: Tidied
No edit summary |
m (→JS Folding from the right: Tidied) |
||
Line 4,445:
(fold and foldr examples)
<syntaxhighlight lang="javascript">(() => {
"use strict";
//
// Folding from right to left,
Line 4,454 ⟶ 4,455:
// fromRoman :: String -> Int
const fromRoman = s =>
([r, n], l) =>
)[1];
// charVal :: Char -> Maybe Int▼
▲ I: 1,
▲ V: 5,
C: 100,▼
D: 500,▼
M: 1000▼
};▼
// ----------------------- TEST ------------------------▼
const
'MDCLXVI', 'MCMXC', 'MMVIII', 'MMXVI', 'MMXVII'▼
.map(fromRoman)
.join("\n");
▲ a
▲ );
▲ return main();
})();</syntaxhighlight>
{{Out}}
|