UNPKG

algs4js

Version:

Basic algorithms and data structures implemented with es6

69 lines (61 loc) 1.88 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } /** * Class DecimalToRomanNumerals * * Provides simple string algorithm functionality. */ var DecimalToRomanNumerals = function () { function DecimalToRomanNumerals() { _classCallCheck(this, DecimalToRomanNumerals); } _createClass(DecimalToRomanNumerals, null, [{ key: 'convert', value: function convert(num) { var decimals = num.toString().split('').reverse(); var roman = []; for (var i = 0; i < decimals.length; i++) { roman.unshift(this.numberMap[decimals[i] * Math.pow(10, i)]); } return roman.join(''); } }]); return DecimalToRomanNumerals; }(); DecimalToRomanNumerals.numberMap = { 1: 'I', 2: 'II', 3: 'III', 4: 'IV', 5: 'V', 6: 'VI', 7: 'VII', 8: 'VIII', 9: 'IX', 10: 'X', 20: 'XX', 30: 'XXX', 40: 'XL', 50: 'L', 60: 'LX', 70: 'LXX', 80: 'LXXX', 90: 'XC', 100: 'C', 200: 'CC', 300: 'CCC', 400: 'CD', 500: 'D', 600: 'DC', 700: 'DCC', 800: 'DCCC', 900: 'CM', 1000: 'M', 2000: 'MM', 3000: 'MMM' }; exports.default = DecimalToRomanNumerals;