Quick actions

cmd+k|ctrl+k

Navigation

Languages

nthFibonacci

Snippet info

Language

JavaScript

Visibility

public

Author

peter

Created

2016-12-16T14:51:30Z

Updated

2016-12-16T14:51:30Z

const nthFibonacci = (n) => {  
  const v5 = Math.sqrt(5)
  const Phi = (v5 + 1) / 2
  const phi = Phi - 1
  
  return Math.round(
      Math.pow(Phi, n) / v5 - Math.pow(-phi, n) / v5)
};



console.log(nthFibonacci(6));
// function fibonacci_nth(i){
//     var v5 = Math.sqrt(5),
//         Phi = ( v5 + 1 ) / 2,
//         phi = Phi-1;

//     return Math.round( Math.pow(Phi, i) / v5 - Math.pow(-phi, i) / v5 );
// }
INFO