Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript roman to integer

const values = new Map([
  ['I', 1],
  ['V', 5],
  ['X', 10],
  ['L', 50],
  ['C', 100],
  ['D', 500],
  ['M', 1000],
]);

function romanToInt(string) {
  let result = 0,
    current, previous = 0;
  for (const char of string.split("").reverse()) {
    current = values.get(char);
    if (current >= previous) {
      result += current;
    } else {
      result -= current;
    }
    previous = current;
  }
  return result;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert an array of strings to numbers 
Javascript :: js show span for 5 seconds 
Javascript :: start react 
Javascript :: create react project 
Javascript :: 50 50 chance javascript 
Javascript :: puppeteer headless false 
Javascript :: js post 
Javascript :: javascript regex french phone number 
Javascript :: change display javascript 
Javascript :: javascript disable input 
Javascript :: uuid react 
Javascript :: setup new angular project 
Javascript :: get html attribute value in js 
Javascript :: npm global flag 
Javascript :: javascript get scroll position 
Javascript :: get text selected option jquery 
Javascript :: js redirect to relative url 
Javascript :: mayoe que menor que 
Javascript :: open link in new tab jquery 
Javascript :: javascript listen for double click 
Javascript :: jquery set checkbox 
Javascript :: jquery style display 
Javascript :: how express serve public folder 
Javascript :: jquery show for 5 seconds 
Javascript :: Appium press Enter on android with js 
Javascript :: @types react-router-dom 
Javascript :: turn object into string javascript 
Javascript :: get random number in solidity 
Javascript :: include node_modules from search vscode 
Javascript :: react clear form after save 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =