Published
Edited
Aug 20, 2018
Insert cell
Insert cell
Insert cell
Insert cell
async function* fibgen(filterFunction = (value) => { return value; }) {
let [nextToLast, last] = [1, 0];
while(true) {
[nextToLast, last] = [last, nextToLast + last];
if(filterFunction(last)) {
await Promises.delay(delay);
yield last;
}
}
}
Insert cell
{
const trueIfEven = (value) => { return value % 2 === 0; };
const generator = fibgen(trueIfEven);
const iterator = generator[Symbol.asyncIterator]();
let outStr = '';
let i = 1;
const sequence = [];
while (true) {
const {done, value} = await iterator.next();
if (done) return;
sequence.push(value);
if (sequence.length >= maxLength){
sequence.shift();
}
yield sequence.join(', ');
}
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more