Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript fibonacci sequence recursion

// Time complexity O(2^n)
function fibonacci(num){
    if(num < 2) return num;
    return fibonacci(num - 2) + fibonacci(num - 1)
}

console.log(fibonacci(2)) // 1
Source by medium.com #
 
PREVIOUS NEXT
Tagged: #javascript #fibonacci #sequence #recursion
ADD COMMENT
Topic
Name
3+3 =