🚨
Spoiler alert: This post contains spoilers for Project Euler.
Problem 2

Sum of the Even Fibonacci Numbers
JS Solution 1
JS Solution 2
I am awful at writing math proofs. But I happen to know that every 3rd fibonacci is even. Which means we could eliminate the modulo check.
In words, my understanding is:
- the sum of 2 odd numbers is always even
- the sum of an even and odd number is always odd
- the fibonacci sequence creates 2x as many odd numbers as it does even, because every even number is summed with an odd number (the numbers before, and after it in the sequence)
- Two odds sum to an even
- An odd and an even sum to an odd
- An odd and an even sum to an odd
- Two odds sum to an even
You can see how this odd-odd-even pattern repeats.
Let's modify the program to skip numbers. This requires an extra var but we skip the modulo check.
Conclusion
It's hard to see the speedup on this one, since the fibonacci sequence tends towards an out of bounds number before performance becomes an issue. But in theory the second solution is faster.