Given a string, turn each character into its ASCII character code and join them together to create a number -let's call this number total1:'ABC'-->'A'=65,'B'=66,'C'=67-->656667
Then replace any incidence of the number 7with the number 1, and call this number 'total2':
total1 =656667^
total2 =656661^
Then return the difference between the sum of the digits in total1 and total2:(6+5+6+6+6+7)-(6+5+6+6+6+1)-------------------------6
题目翻译:给定一个字符串,将字符串的每一个字母转成ASCII码,然后拼接到一起,得到第一个数字`total1`,将`total1`中的数字`7`替换成数字`1`,得到第二个数字`total2`,最后返回total1中各位数字之和与total2中的各位数字之和的差
题解一:
// 题解一:// match() 方法可在字符串内检索指定的值,或找到一个或多个正则表达式的匹配。返回匹配结果的数组。functioncalc(x){var xA =''for(let i=0;i<x.length;i++){
xA += x.substr(i,1).charCodeAt()}return(xA.match(/7/g)||[]).length *6;}
题目:Given a string, turn each character into its ASCII character code and join them together to create a number - let's call this number total1:'ABC' --> 'A' = 65, 'B' = 66, 'C' = 67 --> 656667Then replace any incidence of the number 7 with the nu