Exercise 2: The Relevance-Sorting Heuristic — Possible Solution ==================================================================== WHAT THE HEURISTIC DOES ------------------------------ Each merged recipe result carries a matchedIngredients array listing which of the user's own expiring ingredients that particular recipe uses. Sorting the recipe list by matchedIngredients.length, in descending order, places recipes that use the largest number of the user's actually-expiring items at the top of the list, ahead of recipes that only happen to use one of them. HOW THIS SERVES THE ORIGINAL FEATURE'S INTENT ------------------------------ Chapter 1 described the recipe-lookup feature as suggesting recipes that use ingredients close to expiring - the underlying goal being to help the user actually use up food before it goes to waste, not simply to return any recipe that happens to contain one matching ingredient somewhere in a long list. A recipe using three of the user's expiring items is a much more useful suggestion, for that specific goal, than one using only one - sorting by matchedIngredients.length surfaces exactly the recipes that would help the most food get used up in a single meal, directly serving the feature's real purpose rather than just its literal search criteria. WHY THIS WORKS AS AN ANSWER ------------------------------ It correctly explains what the sort does mechanically (ranking by how many expiring ingredients each recipe matches), and correctly connects that to the feature's actual underlying goal from Chapter 1 - reducing food waste by using up as much expiring food as possible at once, not merely returning any recipe that technically qualifies.