function VisualizeSimpleAndSurprisingSort(A) {
A = A.slice();
const n = A.length;
let steps = A.slice();
const swaps = [];
for (let i = 0; i < n; ++i) {
for (let j = 0; j < n; ++j) {
if (A[i] < A[j]) {
[A[j], A[i]] = [A[i], A[j]];
swaps.push({ i, j });
steps = steps.concat(A.slice());
}
}
}
return Plot.plot({
marks: [
Plot.cell(steps, {
x: (d, g) => g % n,
y: (d, g) => Math.floor(g / n),
fill: steps,
stroke: steps
}),
Plot.arrow(swaps, {
x1: "i",
x2: "j",
y: (d, t) => t
})
],
axis: null,
x: { padding: 0 },
y: { padding: 0 },
color: { scheme: "warm" }
});
}