Answers for "nth value of the Fibonacci sequence in js"

0

how to get nth fibonacci javascript

function nthFib(n) {
	if(n <= 2) return n -1;
  return nthFib(n - 2) + nthFib(n - 1);
}
Posted by: Guest on June-27-2020
0

nth value of the Fibonacci sequence in js

function fibonacci(n) {
	// write your solution here
    let fibo = [0, 1]
    for (var i = 2; i <= n; i++) {
        fibo[i] = fibo[i - 1] + fibo[i - 2];
    }
    return fibo[n] 
}

console.log(`fibonacci value at position 5: ${fibonacci(5)}`)
Posted by: Guest on March-17-2022

Code answers related to "nth value of the Fibonacci sequence in js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language