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

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