Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { Material } from "https://esm.town/v/tmcw/Material";
import { Recipe } from "https://esm.town/v/tmcw/Recipe";
export function sort(recipes: Map<string, Recipe>, materials: Material[]) {
const have = new Set(materials.map((m) => m.name));
return Array.from(recipes.values()).map((recipe) => {
return {
recipe,
weight: recipe.ingredients.filter((ingredient) => {
return have.has(ingredient.material.name);
}).length,
};
}).sort((a, b) => {
return b.weight - a.weight;
}).map((r) => r.recipe);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
November 16, 2023