JavaScript Recipe Batches: Two Approaches Quiz
Two seeded ways to compute how many full batches can be produced from available materials (imperative loop with Math.min and a reduce-based variant), plus two companions on missing-key handling and zero-quantity edge cases.
Question Bank
Hard
JavaScript
quiz
arrays
math
interview-prep
966 views
11
Implement batches(recipe, available) so it returns the maximum number of whole batches that can be produced, returning 0 if any required material is missing from available.
Examples
Example 1:
Input: batches({materialA: 2, materialB: 40, materialC: 20}, {materialA: 5, materialB: 120, materialC: 500})
Output: 2
Explanation: ratios are 2.5, 3, and 25; the limiting material allows two whole batches.Example 2:
Input: batches({materialA: 100, materialB: 4, materialC: 10, materialD: 5}, {materialA: 1288, materialB: 9, materialC: 95})
Output: 0
Explanation: materialD is missing from available, so the recipe cannot be made even once.3 more questions, with full solutions and explanations, are available for premium members.
Upgrade to Premium