Public
Edited
Apr 28, 2024
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
let data = [];

let array;

for (let i = 0; i < repeats; ++i) {
array = mkArray();
sortHalfArray(array);
data = data.concat(
array.map((d, j) => Object.assign({ i }, { x: j, y: d }))
);
}

return data;
}
Insert cell
data
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
/**
* Sort the array for only n times.
**/
sortHalfArray = (array, n = dataLength - analysisLength) => {
let tmp;

for (let i = 0; i < n; ++i) {
for (let j = 0; j < dataLength - i - 1; ++j) {
if (array[j] > array[j + 1]) {
tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
}

return array;
}
Insert cell
mkArray = () => {
let array = [...new Array(dataLength)].map((d) => Math.random());

array = [...new Array(dataLength)].map((d, i) => i);

d3.shuffle(array);

return array;
}
Insert cell
d3 = require("d3")
Insert cell
width = 800
Insert cell
Insert cell
snipaste_20240425_214740 = FileAttachment("Snipaste_2024-04-25_21-47-40.png").image()
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