Sha256: 7023243926d76ab78e6e9b5fb8e47408b0fe52e80822a0a21f7b01159acb74ce

Contents?: true

Size: 746 Bytes

Versions: 73

Compression:

Stored size: 746 Bytes

Contents

'use strict';

module.exports = function (number) {
  var result = '';
  var numbers = number;
  var mappings = [
    {arabic: 1000, roman: 'M'},
    {arabic: 900, roman: 'CM'},
    {arabic: 500, roman: 'D'},
    {arabic: 400, roman: 'CD'},
    {arabic: 100, roman: 'C'},
    {arabic: 90, roman: 'XC'},
    {arabic: 50, roman: 'L'},
    {arabic: 40, roman: 'XL'},
    {arabic: 10, roman: 'X'},
    {arabic: 9, roman: 'IX'},
    {arabic: 5, roman: 'V'},
    {arabic: 4, roman: 'IV'},
    {arabic: 1, roman: 'I'}
  ];

  for (var i = 0; i < mappings.length; i++) {
    var mapping = mappings[i];
    while (numbers >= mapping.arabic) {
      result = result + mapping.roman;
      numbers = numbers - mapping.arabic;
    }
  }

  return result;
};

Version data entries

73 entries across 73 versions & 1 rubygems

Version Path
trackler-2.2.1.159 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.158 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.157 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.156 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.155 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.154 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.153 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.152 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.151 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.150 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.149 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.148 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.147 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.146 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.145 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.144 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.143 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.142 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.141 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.140 tracks/javascript/exercises/roman-numerals/example.js