Message from JavaScript discussions

September 2017

— If you are interested, please feel free to contact me on private

— 

/*Hello guys please i am trying to use the for loop to write the fibonacci sequence can you guys tell me what i am doing wrong i am using my knowledge in python to do this but it is not working*/
var m = function(n){
var a = 0
var b = 1
for(var i = 0, i<n, i++){
a,b = b, a+b
}
return a;
};

console.log(m(4));

— I don't think JS can do value unpacking on assignment

— Meaning

a, b = b, a

is not a thing that works in JS

— In fact I think Python might be one of the only languages where you can do that

— Wow nice i didn't know that. so please is there a way one can write the fibonacci calculation using a for loop?

Message permanent page

— Wait, rust can do it too, with slightly different syntax

— Let (a, b) = (b, a)

— Yes, you just need to swap/change the variables normally

— Var m = function(n){
var a = 0;
var b = 1;
for(var i = 0, i<n, i=i+1){
a = b;
b = a + b;
};
return a;
};

console.log(m(4));

//so this should work?

Message permanent page

— Just try it?

— Your Computer won't blow up