I have created a function to generate fibonacci series using es6 generators:
//WARNING CAUSES INFINITE LOOP
function* fibonacci(limit = Infinity) {
let current = 0
let next = 1
while (current < limit) {
yield current
[current, next] = [next, current + next]
}
}
for (let n of fibonacci(200)) {
console.log(n)
}
The above function doesn't swap the two numbers while if done normally in any other function swaps the two. On running this function I get an infinite loop. Why doesn't the variable swap work?