This file contains hidden or 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
const sum = (a, b) => { | |
if (a == 0) return b; | |
if (b == 0) return a; | |
let newA = a ^ b; | |
let newB = (a & b) << 1; | |
return sum(newA, newB); | |
} | |
const a = 10, b = 5; | |
console.log(sum(a, b)); // 15 |
This file contains hidden or 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
// const fib = (num) => { | |
// if (num <= 0) return 0; | |
// if (num === 1 || num === 2) return 1; | |
// if (num > 2) { | |
// let prev = 1, next = 1; | |
// for (let i = 3; i <= num; i++) { | |
// let sum = prev + next; | |
// prev = next; | |
// next = sum; | |
// } |
NewerOlder