Having an hour to spare recently I decided to solve the common problem of converting from Hindu-Arabic to Roman numerals. Below are two different solutions to solving this problem, taking advantage of many ES2015 additions in the process. Both implementations use the lookup table provided below to handle translation of the seven symbols, along with the subtractive form used to avoid four characters being repeated in a row.
The solution above uses the higher-order fold function to
reduce the supplied Arabic number into a Roman numeral equivalent.
Combined with using a two element array as a form of tuple that we are able to deconstruct at each level, this forms a very descriptive implementation.
## Solution 2
The second solution follows a typical head-tail recursive pattern, taking advantage of the call-stack to return the built-up translation. Deconstruction has been taken even further in this example, highlighting how it is possible to pull out not only a single element but elements within elements from an array subject.