Public
Edited
Dec 17, 2023
Paused
Insert cell
Insert cell
Insert cell
HASH(input)
Insert cell
d3.sum("rn=1,cm-,qp=3,cm=2,qp-,pc=4,ot=9,ab=5,pc-,pc=6,ot=7".split(","), HASH)
Insert cell
d3.sum(input.split(","), HASH)
Insert cell
HASH = function (string) {
let value = 0;

for (let i = 0; i < string.length; ++i) {
// Determine the ASCII code for the current character of the string.
const a = string.charCodeAt(i);
// Increase the current value by the ASCII code you just determined.
value += a;
// Set the current value to itself multiplied by 17.
value *= 17;
// Set the current value to the remainder of dividing itself by 256.
value %= 256;
}

return value;
}
Insert cell
Insert cell
boxes = {
const boxes = new Array(256).fill(0).map(() => []);

for (const code of input.split(",")) {
const [, label, op, focal] = code.match(/(\w+)([-=])(\d*)/);
const box = HASH(label);
if (op === "-") {
const i = boxes[box].findIndex((d) => d.label === label);
if (i > -1) boxes[box].splice(i, 1);
} else {
const i = boxes[box].findIndex((d) => d.label === label);
if (i > -1) boxes[box].splice(i, 1, { label, focal });
else boxes[box].push({ label, focal });
}
}
return boxes;
}
Insert cell
focusingPower = d3.sum(
boxes,
(box, i) => (i + 1) * d3.sum(box, ({ focal }, j) => (j + 1) * +focal)
)
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