typeRomanNumeral='I'|'V'|'X'|'L'|'C'|'D'|'M';constRomanNumerals:Record<RomanNumeral,number>={I:1,V:5,X:10,L:50,C:100,D:500,M:1000};/**
* Convert a string of Roman Numerals to an integer
* @param input String of Roman Numerals. Invalid characters are not considered.
*/functionsolution(input:string):number{returnArray.from(input).map(n=>RomanNumerals[n]).filter(Number).reduce((total,val,idx,arr)=>{if(val>=(arr[idx+1]||0)){return(total+=val);}else{return(total-=val);}},0);}
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
TypeScript