输入:firstWord = "acb", secondWord = "cba", targetWord = "cdb"
输出:true
解释:
firstWord 的数值为 "acb" -> "021" -> 21
secondWord 的数值为 "cba" -> "210" -> 210
targetWord 的数值为 "cdb" -> "231" -> 231
由于 21 + 210 == 231 ,返回 true
/**
* @param {string} firstWord
* @param {string} secondWord
* @param {string} targetWord
* @return {boolean}
*/
var isSumEqual = function (firstWord, secondWord, targetWord) {
function str2Num(str) {
const num = Number(str.split('').map(char => char.charCodeAt() - 97).join(''))
// console.log(num)
return num
}
return str2Num(firstWord) + str2Num(secondWord) === str2Num(targetWord)
};