console.log(t);
[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987]
fichier code
code
En action :
let Fib = {[Symbol.iterator]() {
let n1 = 1,
n2 = 1;
return {
[Symbol.iterator]() {
return this;
},
next() {
let current = n2;
n2 = n1;
n1 = n1 + current;
if (current <= 1000) { //sinon la boucle est infinie
return {
value: current,
done: false
};
} else {
return {
done: true
};
}
return {
value: current,
done: false
};
},
return () {
console.log(
`stop`
);
return {
done: true
};
}
};
}
};
t = Array.from(Fib)
console.log(t);