Skip to content

Instantly share code, notes, and snippets.

@DanWilkerson
Created November 8, 2013 14:31
Show Gist options
  • Save DanWilkerson/7371808 to your computer and use it in GitHub Desktop.
Save DanWilkerson/7371808 to your computer and use it in GitHub Desktop.
Fibonacci Generator in Javascript for #Code140. Requires BigInteger by SilentMatt. Working web application using below code can be found at http://www.danwilkerson.com/apps/code140/fibonacci/fibonacci.html
/***** Dan Wilkerson * @notdanwilkerson *****/
// Simple function to return the value of the nth number of the Fibonacci sequence.
// Requires BigInteger by silentmatt ( http://silentmatt.com/biginteger/ )
// To see a working webapplication that uses this code visit
// http://www.danwilkerson.com/apps/code140/fibonacci/fibonacci.html
function fibonachocheese(number){
if (number % 1 !== 0 || number < 0 || number > 100000) {
return 'Please enter a valid integer from 0 - 100000';
} else {
var numOne = BigInteger._1;
var numTwo = BigInteger._0;
var num = BigInteger._0;
for(i = 0; i < number; i ++) {
num = numOne.add(numTwo);
numOne = numTwo;
numTwo === BigInteger._0 ? numTwo = BigInteger._1 : numTwo = num;
}
number === BigInteger._1 ? num = BigInteger._1 : '';
return num;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment