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.119 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.118 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.117 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.116 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.115 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.114 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.113 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.111 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.110 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.109 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.108 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.107 tracks/javascript/exercises/roman-numerals/example.js
trackler-2.2.1.106 tracks/javascript/exercises/roman-numerals/example.js