Created
June 27, 2024 21:08
-
-
Save cfjedimaster/4070cbeb3665630a297f84ed6d68c767 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
So, I struggled with the logic of - given we have 2 or 3 arrays, what items exist in ALL 3 | |
Idea by @falken on Masto | |
*/ | |
let numArrays = 0; | |
if(filter.title) numArrays++; | |
if(filter.duration) numArrays++; | |
if(filter.ingredient) numArrays++; | |
let idBag = {}; | |
let obBag = {}; | |
if(filter.title) { | |
for(t of byTitle) { | |
if(!idBag[t.id]) idBag[t.id] = 1; | |
else idBag[t.id]++; | |
obBag[t.id] = t; | |
} | |
} | |
if(filter.duration) { | |
for(t of byDuration) { | |
if(!idBag[t.id]) idBag[t.id] = 1; | |
else idBag[t.id]++; | |
obBag[t.id] = t; | |
} | |
} | |
if(filter.ingredient) { | |
for(t of byIngredient) { | |
if(!idBag[t.id]) idBag[t.id] = 1; | |
else idBag[t.id]++; | |
obBag[t.id] = t; | |
} | |
} | |
for(let id in idBag) { | |
if(idBag[id] === numArrays) result.push(obBag[id]); | |
} | |
resolve(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment