Published
Edited
Apr 28, 2021
Insert cell
Insert cell
expected = [0, 1, 1, 2, 3, 5, 8, 13]
Insert cell
{
function fib(n) {
if (n === 0) return 0
if (n === 1) return 1
return fib(n - 1) + fib(n - 2)
}

return Array.from({ length: 8 }).map((_, index) => fib(index))
}
Insert cell
{
const fib = Array.from({ length: 8 })
fib[0] = 0
fib[1] = 1
for (let n = 2; n < fib.length; n += 1) {
fib[n] = fib[n - 1] + fib[n - 2]
}
return fib
}
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