Skip to content

Instantly share code, notes, and snippets.

@hassan-maavan
Created September 18, 2020 19:11
Show Gist options
  • Save hassan-maavan/99d6573d0ddd21c7ed73569b24697636 to your computer and use it in GitHub Desktop.
Save hassan-maavan/99d6573d0ddd21c7ed73569b24697636 to your computer and use it in GitHub Desktop.
16+18=214 For this Kata you will have to forget how to add two numbers together. In simple terms, our method does not like the principle of carrying over numbers and just writes down every number it calculates :-) You may assume both integers are positive integers https://www.codewars.com/kata/5effa412233ac3002a9e471d/train/javascript
num1 = ('' + num1).split('').reverse()
num2 = ('' + num2).split('').reverse()
let max = Math.max(num1.length, num2.length)
let str = [];
for(let i = 0; i < max; i++)
str.push((parseInt(num1[i]) || 0) + (parseInt(num2[i]) || 0))
num1 = str.reverse().join('');
return parseInt(num1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment