JavaScript Problem: Computing a Fibonacci Sequence

preview_player
Показать описание
In this JavaScript problem you will see examples of using the while loop and recursion to determine a fibonacci sequence.
For a complete list of all our tutorials:

Рекомендации по теме
Комментарии
Автор

I find this channel really useful. Thank you for all your effort

fastLinkNg
Автор

Honestly, you lost me but in watching your vid I found out why my for loop wasn't working so thumbs up my man

jonathancarter
Автор

extremely simple, easy to understand and efficient. I'm amazed.

navinnavneet
Автор

My answer for this is,


function fibonacci(num, signature) {
for(i = 0; i < signature; i++) {
num.push(num[num.length - 1] + num[num.length - 2]
}
return num
}

michaelz
Автор

The labels chosen were specific enough to be useful on the while loop. Being less practiced with while loops but wanting to use them for the Fibonacci sequence, I was lost on others' variable updates exemplified below. Thanks for elucidating variables for beginners.
let fib = n => {
let [a, b, temp] = [1, 0];
while (n >= 1) {
temp = a;
a = a + b;
b = temp;
n - -;
}
return b;
}
Arrow function, special type of element variable assignment, reverse of common starting values, base case placed succintly, names such as temp and a that can intimidate.

crystalchaung
Автор

It is hard to find these algorithm things thoroughly explained, Thank you for taking your time to share these
difficult yet important concepts. Thank you from my heart.

rotrose
Автор

Thanks for the vid. This made it a little easier to understand how it works.

tjmarshLoL
Автор

Hello, teacher!
Here's my solution:
function makeFibonacci(arr, range) {
range = range - 2;
var n1 = arr[0];
var n2 = arr[1];
fibonacci.push(n1);
fibonacci.push(n2);
for(var i = 0; i < range; i++){
var n3 = fibonacci[i] + fibonacci[i + 1];
fibonacci.push(n3);
}
return fibonacci;
}
console.log(makeFibonacci([1, 2], 12));

peristiloperis
Автор

the 2 methods are very good explainations, thank you teacher

bw
Автор

I dont think this problem needs such a long drawn out solution:
function calcfib(arr, num){
if(num<=arr.length){return arr}
for(let i=arr.length;i<num;i++){
arr[i]=arr[i-1]+arr[i-2]
}
return arr
}

console.log(calcfib([1, 1], 2))

marketingdesigncoding
Автор

Hello there, aren't you wrong in fibonacci 15? the result should be 610 instead of 377, according to my calculations...or do we count with the zero as a first number, then it would be 377??

zdenekbidrman
Автор

why in the while loop writing this statement, , I just dont understand it

lilitavetisyan
Автор

does it is the fastest way of counting fibinacci?

konstantinkkk
Автор

First slide has a huge spelling mistake. I can't listen without wanting to fix it.

columcreed
welcome to shbcf.ru