Skip to content

Instantly share code, notes, and snippets.

@cironunes
Created September 7, 2011 12:21
Show Gist options
  • Save cironunes/1200418 to your computer and use it in GitHub Desktop.
Save cironunes/1200418 to your computer and use it in GitHub Desktop.
Fibonacci number script
var Fibonacci = function () {
//private
var nums = [0,1];
return {
pushNumbers: function (q) {
//check if value pass to this method is a number
//if not set it to 0
q = typeof q === 'number' ? q : 0;
for (var i = 0; i < q; i ++) {
//get actual size and calc next number to push in array
var actSize = nums.length - 1,
next = nums[actSize] + nums[actSize - 1];
nums.push(next);
}
},
getSeq: function () {
return nums;
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment