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.139 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.138 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.137 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.136 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.135 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.134 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.133 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.132 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.131 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.130 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.129 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.128 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.127 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.126 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.125 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.124 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.123 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.122 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.121 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.120 tracks/javascript/exercises/roman-numerals/example.js