var addTwoNumbers = function(l1, l2) {
var _l1 = "", _l2 = "", answer = 0, answerArr = []
for(var i = l1.length-1; i >= 0; i--){
_l1 = _l1 + l1[i]
}
for(var i = l2.length-1; i >= 0; i--){
_l2 = _l2 + l2[i]
}
answer = parseInt(_l1) + parseInt(_l2)
for(var i = 0; i < answer.toString().length; i++){
answerArr.push(parseInt(answer.toString()[i]))
}
return answerArr.reverse()
};
console.log(addTwoNumbers([2,4,3], [5,6,4]))
No comments:
Post a Comment