Solving Popular Algorithms: Add Strings

Me, struggling to solve this problem
Remember this?
let arr1 = num1.split("")
let arr2 = num2.split("")
let numZs = 0
if (num1.length > num2.length) {
numZs = num1.length - num2.length
while (numZs > 0) {
arr2.unshift("0")
numZs--
}
} else {
numZs = num2.length - num1.length
while (numZs > 0) {
arr1.unshift("0")
numZs--
}
}
let results = []
let secondDig = 0
for (let i = arr1.length-1; i >= 0; i--) {
let sumNum = parseInt(arr1[i]) + parseInt(arr2[i])
if (sumNum >= 10) {

arr1[i-1] = (parseInt(arr1[i-1]) + 1).toString()
let gettingSecondDig = sumNum.toString().split("")
secondDig = gettingSecondDig[1]
if (i === 0) {
results.unshift(sumNum.toString())
} else {
results.unshift(secondDig)
}
} else {
results.unshift(sumNum.toString())
}
}
addStrings = (num1, num2) => {
let arr1 = num1.split("")
let arr2 = num2.split("")
let numZs = 0
if (num1.length > num2.length) {
numZs = num1.length - num2.length
while (numZs > 0) {
arr2.unshift("0")
numZs--
}
} else {
numZs = num2.length - num1.length
while (numZs > 0) {
arr1.unshift("0")
numZs--
}
}

let results = []
let secondDig = 0
for (let i = arr1.length-1; i >= 0; i--) {
let sumNum = parseInt(arr1[i]) + parseInt(arr2[i])
if (sumNum >= 10) {

arr1[i-1] = (parseInt(arr1[i-1]) + 1).toString()
let gettingSecondDig = sumNum.toString().split("")
secondDig = gettingSecondDig[1]
if (i === 0) {
results.unshift(sumNum.toString())
} else {
results.unshift(secondDig)
}
} else {
results.unshift(sumNum.toString())
}
}

return results.join("")
}
Me, now that I’ve solved this problem

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store