mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-21 23:36:15 -04:00
refactor(types): fixed types
This commit is contained in:
parent
59c2a46b53
commit
2d76a4fbb6
1 changed files with 3 additions and 3 deletions
|
@ -29,10 +29,10 @@ path: '/roman-numeral-converter'
|
|||
<script lang="ts">
|
||||
import {Component} from 'nuxt-property-decorator'
|
||||
import {CopyableMixin} from '@/mixins/copyable.mixin'
|
||||
import Tool from '@/components/Tool'
|
||||
import Tool from '@/components/Tool.vue'
|
||||
|
||||
function arabicToRoman(num:number) {
|
||||
const lookup = {M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4, I: 1}
|
||||
const lookup: { [key: string]: number } = {M: 1000, CM: 900, D: 500, CD: 400, C: 100, XC: 90, L: 50, XL: 40, X: 10, IX: 9, V: 5, IV: 4, I: 1}
|
||||
let roman = ''
|
||||
for (const i in lookup) {
|
||||
while (num >= lookup[i]) {
|
||||
|
@ -44,7 +44,7 @@ function arabicToRoman(num:number) {
|
|||
}
|
||||
|
||||
const romanToArabic = (s: string) => {
|
||||
const map = {I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000}
|
||||
const map: { [key: string]: number } = {I: 1, V: 5, X: 10, L: 50, C: 100, D: 500, M: 1000}
|
||||
return [...s].reduce((r, c, i, s) => map[s[i + 1]] > map[c] ? r - map[c] : r + map[c], 0)
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue