Last active
July 28, 2020 12:50
-
-
Save oreillyross/6a8df2a47fa3b44b066206c119b1b82d to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/kawusad Fibannaci using generator function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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