Public
Edited
Dec 26, 2021
Insert cell
Insert cell
viewof x = Inputs.number({value: 4, label: "Enter the number:"})
Insert cell
jazr(x)
Insert cell
function jazr (x, guess=1.0) {
let threshold = x / 1e6
let average = (x, y) => (x+y)/2
let goodEnough = (x, guess) => Math.abs(guess*guess - x) < threshold
let improve = (x, guess) => average(guess, x/guess)
if (x == 0.0) return 0.0
else if (goodEnough(x, guess)) return guess;
else return jazr(x, improve(x, guess))
}
Insert cell
Insert cell
range = [...Array(11).keys()];
Insert cell
a1 = range.map(jazr)
Insert cell
a2 = range.map(Math.sqrt)
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