Public
Edited
Dec 21, 2022
3 forks
3 stars
Insert cell
Insert cell
Insert cell
statements = data
.trim()
.split("\n")
.map((l) =>
l
.replace(/([a-z]+)/g, "$1()")
.replace("():", " = () =>")
.replace(/^/, "const ")
)
Insert cell
part1 = eval(`(() => {
${statements.join(";")}
return root()
})()`)
Insert cell
Insert cell
Insert cell
fn = eval(`(x) => {
${statements
.map((l) => {
if (l.includes("root =")) return l.replace(/[+-/*]/, "-");
else if (l.includes("humn =")) return "const humn = () => x";
else return l;
})
.join(";")}
return root()
}`)
Insert cell
Insert cell
x = [3e12, 4e12]
Insert cell
Insert cell
Insert cell
m = (fn(x[1]) - fn(x[0])) / (x[1] - x[0])
Insert cell
b = fn(x[0]) - m * x[0]
Insert cell
part2 = -b / m
Insert cell
Insert cell
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