Skip to content

alaindeurveilher/react-roman-to-arabic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React Roman <-> Arabic

Converts a Roman number into its Arabic number, and vice-versa

Motivation

This project was part a challenge set with some friends and collegue to build the best Roman number to Arabic converter.

Limitation

Only numbers in a range of 1 to 4999 are supported

Principle

My solution is based on the construction of a dictionnary of Roman numbers from numeric Arabic numbers. Typed in Roman numbers are then searched in that dictionnary.

All the algorithm is included in the convert.jsx file.

Implemented rules

  1. Only the following characters are allowed: IVXLCDM
  2. To build the dictionnary, a for loop from 1 to 4999 is used
  3. To transform the Arabic number into Roman we divide first by 1000, then 500, 100, 50, 10, 5 and finally by 1
  4. For each step, for the number of times the number is divisible we replace by the corresponding Roman letter:
    • 1000 -> M
    • 500 -> D
    • 100 -> C
    • 50 -> L
    • 10 -> X
    • 5 -> V
    • 1 -> I
  5. After that some convertion rules are applied, because in Roman numbers, sometimes a substraction is written. For instance instead of writting four like this IIII, Roman writes instead five minus one like this IV
  6. The convertion from Roman number to Arabic is then just checking its existence in the dictionnary

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.

The page will reload if you make edits.
You will also see any lint errors in the console.

npm test

Launches the test runner in the interactive watch mode.
See the section about running tests for more information.

npm run build

Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.

The build is minified and the filenames include the hashes.
Your app is ready to be deployed!

See the section about deployment for more information.

npm run eject

Note: this is a one-way operation. Once you eject, you can’t go back!

If you aren’t satisfied with the build tool and configuration choices, you can eject at any time. This command will remove the single build dependency from your project.

Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.

You don’t have to ever use eject. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.

About

Convert Roman number <-> Arabic number

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published