Snippets Collections
//First Examples
function fibonacci(n) {
	const list = [0, 1];
	for (let x = 2; x < n + 1; x += 1) {
		list.push(list[x - 2] + list[x - 1]);
	}
	return list[n];
}

console.log(fibonacci(4));

//Second Examples
function fibonacci(nums) {
  
  let fib = [0, 1];
  let data = [];
  
  for(let i = 2; i <= nums; i++) {
    fib[i] = fib[i - 1] + fib[i - 2]; 
    data.push(fib[i]);
  }
  
  return data;
}

//Third Examples
function fibonacci(nums) {
  
  let fib = [0, 1];
  let data = [];
  
  for(let i = 2; i <= nums; i++) {
    fib[i] = fib[i - 1] + fib[i - 2]; 
    data.push(fib[i]);
  }
  
  return data;
}
star

Wed Apr 28 2021 07:08:02 GMT+0000 (Coordinated Universal Time) https://www.codegrepper.com/code-examples/javascript/fibonacci+in+javascript+without+recursion

#fibonacci #javascript #algebra

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension