题目描述
思路分析
就是直接处理,比较麻烦的的是将字符串处理成数组,我用的是正则匹配
代码解析
t input = [
[4],
['100CNY101fen'],
['100HKD102cents'],
['100JPY103sen'],
['100EUR104eurocents'],
['100GBP105pence']
], sum = 0;
input.shift()
console.log('input=>', input);
for (let i = 0; i < input.length; i++) {
console.log('input[i]=>', input[i]);
let count = 0;
let a = JSON.stringify(input[i]).match(/[a-zA-Z]+|[0-9]+(?:\.[0-9]+|)/g);
console.log('a=>', a);
switch (a[1]) {
case 'CNY':
count = (parseInt(a[0]) + parseInt(a[2]) / 1000) * 1
break;
case 'HKD':
count = (parseInt(a[0]) + parseInt(a[2]) / 1000) / 1.23
break;
case 'JPY':
count = (parseInt(a[0]) + parseInt(a[2]) / 1000) / 18.25
break;
case 'EUR':
count = (parseInt(a[0]) + parseInt(a[2]) / 1000) / 0.14
break;
case 'GBP':
count = (parseInt(a[0]) + parseInt(a[2]) / 1000) / 0.12
break;
}
sum += count
}
console.log('sum=>', parseInt(sum));
后话
只是记录,正在找工作中,各位老板缺前端的可以私信,会vue,react,ts,js,22届本科毕业,一年工作经验