Skip to content

Latest commit

 

History

History
14 lines (12 loc) · 244 Bytes

fibonacci_math.md

File metadata and controls

14 lines (12 loc) · 244 Bytes

Fibonacci with math

// 0(1) time complexity
function fibonacci(n) {
    return Math.round(
        (Math.pow((1 + Math.sqrt(5)) / 2, n) -
        Math.pow((1 - Math.sqrt(5)) / 2, n)) /
        Math.sqrt(5)
    );
}

fibonacci(50);