Skip to content

Latest commit

 

History

History

roman

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

This package is written to support the mutual conversion between Roman numerals and Arabic numerals.

Install

  • npm

    npm install --save @algorithm.ts/roman
  • yarn

    yarn add @algorithm.ts/roman

Usage

  • int2roman: Convert an Arabic numeral into a Roman numeral representation.

    import { int2roman } from '@algorithm.ts/roman'
    
    int2roman(1)    // => 'I'
    int2roman(4)    // => 'IV'
    int2roman(9)    // => 'IX'
    int2roman(1437) // => 'MCDXXXVII'
    int2roman(3999) // => 'MMMCMXCIX'
    
    // Out of range
    int2roman(4000) // => An TypeError will be thrown
  • roman2int: Convert an Roman numeral into a Arabic numeral representation.

    import { roman2int } from '@algorithm.ts/roman'
    
    roman2int('I')          // => 1
    roman2int('IV')         // => 4
    roman2int('IX')         // => 9
    roman2int('MCDXXXVII')  // => 1437
    roman2int('MMMCMXCIX')  // => 3999

Related