[JS] Recursive and Iterative solutions
Approach:\nXOR - for adding, but need to deal with carry\n8 = 1000, 9 = 1001\n8 ^ 9 = 0001 \n\nFor carry at the 4th bit, we can use AND\n8 & 9 = 1000 (this show
**Approach:**\nXOR - for adding, but need to deal with carry\n8 = 1000, 9 = 1001\n8 ^ 9 = 0001 \n\nFor carry at the 4th bit, we can use AND\n8 & 9 = 1000 (this shows bit positions from where carry needs to be forwarded to the next bit addition)\n\nsince carry is forwarded to the next bit addition, shift the carry to the left\n=> 8 & 9 << 1 => 10000\n\nthen we add:\n10000 ^ 0001 = 10001 (17)\n\nWill have to keep on doing this until carry is 0.\n\n**Solution 1: Recursive**\n```\nvar getSum = function(a, b) {\n    if(b === 0) {\n        return a;\n    }\n    return getSum(a ^ b, (a & b) << 1);\n};\n```\n\n**Solution 2: Iterative**\n```\nvar getSum = function(a, b) {\n    while(b) {\n        const carry = a & b;\n        a = a ^ b;\n        b = carry << 1;\n    }\n    return a;\n}\n```\n**Example:**\n```\n/*\na = 8 = 1000\nb = 9 = 1001\n\n8 ^ 9 = 0001 = 1\n8 & 9 = 1000 = 8\n1000 << 1 = 10000 = 16\n\na = 00001\nb = 10000\n\n1 ^ 16 = 10001 = 17\n1 & 16 = 00000 = 0\n*/\n```
['Bit Manipulation', 'JavaScript']