Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // The solution is so simple(not easy) compared to other solutions, my brains hurts, but proud of my work!
- function sumFibs(n, a = 0, b = 1) {
- if (a > n) return 0;
- if (a % 2 !== 0) return a + sumFibs(n, a + b, a);
- else return 0 + sumFibs(n, a + b, a);
- }
- sumFibs(10); //1 + 1 + 3 + 5 = 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement