Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

roman to integer fastest way

function romanToInteger(s) {
    let map = {
        I: 1,
        V: 5,
        X: 10,
        L: 50,
        C: 100,
        D: 500,
        M: 1000,
        IV: 4,
        IX: 9,
        XL: 40,
        XC: 90,
        CD: 400,
        CM: 900
    }
    let result = 0;
    for (let i = 0; i < s.length; i++) {
        let current = s[i] + s[i + 1];
        if (map[current] !== undefined) {
            result += map[current];
            i++;
        } else {
            result += map[s[i]];
        }
    }
    return result;
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: get page scrolling amount js 
Javascript :: window alert javascript css 
Javascript :: change origin phaser 
Javascript :: Javascripti functions accepting Flask parameters to display a PDF file with Adobe Embed API 
Javascript :: vuejs.org español 
Javascript :: phaser place on ellipse 
Javascript :: phaser set alpha 
Javascript :: phaser create animation without frame names 
Javascript :: phaser play animation with config.js 
Javascript :: test unitaire javascript 
Javascript :: how to process string calculation in gdscript 
Javascript :: Opposites attract 
Javascript :: hook use effect with class 
Javascript :: nextjs check path 404 
Javascript :: marko js 
Javascript :: Adding A Function To All Node Example With Javascript 
Javascript :: DataTables warning: table id=datatable - Ajax error 
Javascript :: how to delete an element from an array in javascript 
Javascript :: loop on each character js 
Javascript :: js toggle multiple classes 
Javascript :: mongodb find and update array item by id 
Javascript :: how to turn a string into an array javascript 
Javascript :: Lazy Loading 
Javascript :: mongoose update array push multiple 
Javascript :: last item of array javascript 
Javascript :: return statement in javascript 
Javascript :: ilan mask 
Javascript :: svg react native 
Javascript :: loop for of 
Javascript :: set active element javascript 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =