DEV Community

Discussion on: Daily Challenge #287 - 16+18=214

Collapse
 
soorajsnblaze333 profile image
Sooraj (PS)
const noCarryAddition = (num1, num2) => {
  let result = [];
  if (num1.length >= num2.length) {
    num1.toString().split('').reverse().map((n1, index) => result.push(+n1 + +(num2.toString().split('').reverse()[index] || 0)));
  } else {
    num2.toString().split('').reverse().map((n2, index) => result.push(+n2 + +(num1.toString().split('').reverse()[index] || 0)));
  }
  return result.reverse().join('');
}

Took a slightly bigger approach, but it works :)