Skip to content

Instantly share code, notes, and snippets.

View guxuerui's full-sized avatar

Gu Xuerui guxuerui

View GitHub Profile
@guxuerui
guxuerui / getSum.js
Created July 2, 2020 06:38
js两数求和
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
@guxuerui
guxuerui / fib.js
Last active June 22, 2020 09:16
菲波那切数列
// 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;
// }