Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created September 15, 2019 20:39
Show Gist options
  • Select an option

  • Save gkucmierz/e6774bfc73113973bef4ad0cb85f2770 to your computer and use it in GitHub Desktop.

Select an option

Save gkucmierz/e6774bfc73113973bef4ad0cb85f2770 to your computer and use it in GitHub Desktop.
const convertToRoman = num => {
const roman = [...'IVXLCDM'];
const patt = [
[],
[0],
[0, 0],
[0, 0, 0],
[0, 1],
[1],
[1, 0],
[1, 0, 0],
[1, 0, 0, 0],
[0, 2]
];
return [...(num+'')].map((n,i,a)=>patt[n].map(r=>roman[(a.length-1-i)*2+r]).join``).join``;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment