Public
Edited
Aug 30, 2021
4 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const x = [-10,1,5,-66,15,16,100,99,5,6,7];
const xs = module.csort(x);
const y = [];
// There does not appear to be a way to directly treat `xs` as an iterable (e.g. JS array).
for (let i = 0; i < xs.size(); ++i){
y.push(xs.get(i));
}
return y;
}
Insert cell
Insert cell
module = await moduleFromJavaScriptAndWasm(
FileAttachment("test@3.js"),
FileAttachment("test@3.wasm")
);
Insert cell
moduleFromJavaScriptAndWasm = async (jsFileAttachment, wasmFileAttachment) => {
// Source: https://observablehq.com/@ballingt/hello-embind
const wasmLocation = await wasmFileAttachment.url();
const createModule = await require(await jsFileAttachment.url());
return new Promise(resolve => {
createModule({
// By default Emscripten modules expect the .wasm code at ./quick_example.wasm
// and since Observable file attachments don't have predictable names like this
// we override this behavior.
locateFile: function(s) {
return wasmLocation;
}
}).then(m => {
// Something about this .then() locks up Observable
delete m.then;
resolve(m);
});
});
}
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