Malj72
9/12/2017 - 7:22 AM

Fibonacci sequence function

// Mine function

function fibonacci (end) {
    let results = [0,1];
        firstNum = 0;
        secondNum = 1;

    for (var i = 1; i < end; i++) {        
        if (i === firstNum + secondNum) {
            firstNum = secondNum;  
            secondNum = i;
            results.push(i); 
            }    
    }
    return results;
}
console.log(fibonacci(1000));

// Not mine, bit slower, without array
	
function fibonacci(num){
  var a = 1, b = 0, temp;

  while (num >= 0){
    temp = a;
    a = a + b;
    b = temp;
    num--;
  }

  return b;
}