Last active
April 6, 2016 23:05
-
-
Save AntonisFK/b1af6c5cbfef4eb81199c3310fd7ff9f to your computer and use it in GitHub Desktop.
Fibonacci Sequence is the series of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34. iFibonacci(6) => 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// iFibonacci(0) = 0 => 0 | |
// iFibonacci(1) = 1 => 1 | |
// iFibonacci(2) = 1 => 1 | |
// iFibonacci(3) = 1 + 1 => 2 | |
// iFibonacci(4) = 1 + 2 => 3 | |
// iFibonacci(5) = 2 + 3 => 5 | |
// iFibonacci(6) = 3 + 5 => 8 | |
var iFibonacci = function(num){ | |
var num1 = 0; | |
var num2 = 1; | |
var counter = 1; | |
while(num !== counter){ | |
var temp = num2; | |
num2 += num1; | |
num1 = temp; | |
counter ++; | |
} | |
return num2; | |
}; | |
iFibonacci(6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment