Skip to content

Instantly share code, notes, and snippets.

@fa7ad
Created Mar 3, 2018
Embed
What would you like to do?
JS Bin // source https://jsbin.com/safebuh
<!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">
const fibGen = (function () {
let [prev, curr] = [0, 1]
return () => {
;[prev, curr] = [curr, prev + curr]
return prev
}
})()
const vals = Array.from({length: 10}, fibGen)
console.log(vals)
</script>
<script id="jsbin-source-javascript" type="text/javascript">const fibGen = (function () {
let [prev, curr] = [0, 1]
return () => {
;[prev, curr] = [curr, prev + curr]
return prev
}
})()
const vals = Array.from({length: 10}, fibGen)
console.log(vals)</script></body>
</html>
const fibGen = (function () {
let [prev, curr] = [0, 1]
return () => {
;[prev, curr] = [curr, prev + curr]
return prev
}
})()
const vals = Array.from({length: 10}, fibGen)
console.log(vals)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment