Created
March 14, 2016 09:13
-
-
Save OlegLustenko/141f5ec267b16b8c2a89 to your computer and use it in GitHub Desktop.
Adding big numbers JavaScript (from codewars.com)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function add (a, b) { | |
let res = '', c = 0 | |
a = a.split('') | |
b = b.split('') | |
while (a.length || b.length || c) { | |
c += ~~a.pop() + ~~b.pop() | |
res = c % 10 + res | |
c = c > 9 | |
} | |
return res | |
} |
Why you are using the bitwise double NOT operator in line 6. Is this way to handle negative numbers, but then why are you not adding one to them?
I think the double bitwise NOT operator is checking for undefined
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you.. this solves my problem