Skip to content

Instantly share code, notes, and snippets.

@oreillyross
Last active July 28, 2020 12:50
Show Gist options
  • Save oreillyross/6a8df2a47fa3b44b066206c119b1b82d to your computer and use it in GitHub Desktop.
Save oreillyross/6a8df2a47fa3b44b066206c119b1b82d to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/kawusad Fibannaci using generator function
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
/* jshint esnext: true */
function* fibs() {
let a = 0;
let b = 1;
while (true) {
yield a;
[a, b] = [b, a + b];
}
}
var [first, second, third, fourth, fifth, sixth] = fibs();
console.log(first, second, third, fourth, fifth, sixth);
// 5
</script>
<script id="jsbin-source-javascript" type="text/javascript">/* jshint esnext: true */
function* fibs() {
let a = 0;
let b = 1;
while (true) {
yield a;
[a, b] = [b, a + b];
}
}
var [first, second, third, fourth, fifth, sixth] = fibs();
console.log(first, second, third, fourth, fifth, sixth);
// 5
</script></body>
</html>
/* jshint esnext: true */
function* fibs() {
let a = 0;
let b = 1;
while (true) {
yield a;
[a, b] = [b, a + b];
}
}
var [first, second, third, fourth, fifth, sixth] = fibs();
console.log(first, second, third, fourth, fifth, sixth);
// 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment