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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more