Published
Edited
Feb 24, 2019
1 fork
Importers
27 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
difference = (a, b) => {
let ai = new Set(a.ingredients);
let bi = new Set(b.ingredients);

let removedItems = [];
let addedItems = [];
for (let item of ai) if (!bi.has(item)) addedItems.push(item);
for (let item of bi) if (!ai.has(item)) removedItems.push(item);

let changes = [];
const replacementCount = Math.min(addedItems.length, removedItems.length);
for (let i = 0; i < replacementCount; i++) {
const removed = removedItems.pop();
const added = addedItems.pop();
changes.push({ type: "replacement", removed, added });
}

for (let added of addedItems) {
changes.push({ type: "addition", added });
}

for (let removed of removedItems) {
changes.push({ type: "removal", removed });
}

return changes;
}
Insert cell
Insert cell
Insert cell
function symm_diff(a,b) {
const ai = new Set(a.ingredients);
const bi = new Set(b.ingredients);
const a_b = new Set(a.ingredients.filter(d => !bi.has(d)));
const b_a = new Set(b.ingredients.filter(d => !ai.has(d)));
const union = new Set([...a_b].concat([...b_a]));
return union.size;
}
Insert cell
Insert cell
Insert cell
Insert cell
function jaccard_distance(a,b) {
const bi = new Set(b.ingredients);
const inter = new Set(a.ingredients.filter(d => bi.has(d)));
const union = new Set(a.ingredients.concat(b.ingredients));
return 1 - inter.size / union.size;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// White Lady is #7, Aviation is #10
({whitelady:jacc_mat[7], aviation:jacc_mat[10]})
Insert cell
// White Lady is #7, Aviation is #10
({whitelady:symm_mat[7], aviation:symm_mat[10]})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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