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.180 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.179 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.178 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.177 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.176 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.175 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.174 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.173 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.172 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.171 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.170 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.169 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.167 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.166 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.165 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.164 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.163 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.162 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.161 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.160 tracks/javascript/exercises/roman-numerals/example.js