Public
Edited
Feb 6, 2022
Importers
4 stars
Insert cell
Insert cell
CS = require("coffeescript") // CoffeeScript
Insert cell
Insert cell
Insert cell
Insert cell
shuffle = compileCsMd(cshuffle)
Insert cell
Insert cell
shuffle([0, 1, 2, 3, 4], NB) // the working, proof-of-concept, CoffeeScript defined function
Insert cell
Insert cell
randInt = (maxPlusOne) => ~~(Math.random() * maxPlusOne) // sample notebook cell passed to CoffeeScript via the NB Object
Insert cell
TWO = 2 // sample notebook cell value passed to CoffeeScript via the NB Object
Insert cell
Insert cell
compiledCoffeeScript = CS.compile(cleanCsMd(cshuffle), {
bare: true,
literate: true
})
Insert cell
Insert cell
cshuffle.innerHTML
Insert cell
Insert cell
cleanCsMd = (mdCell) => {
let md = ``;
let elems = Array.from(mdCell.children);
for (const child of elems) {
if (child.tagName === "PRE" || elems.length === 1) {
// elems.length === 1 handles the edge case of an md cell that is all code (wrapped in <code></code>)
let text = child.innerText.split("\n");
for (const line of text) {
md += ` ${line}\n`;
}
} else md += child.innerText + `\n\n`;
}
return md;
}
Insert cell
compileCsMd = (mdCell) =>
eval(CS.compile(cleanCsMd(mdCell), { bare: true, literate: true }))
Insert cell
NB = ({ randInt, TWO }) // NB = NoteBook
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