DEV Community

Discussion on: JavaScript Challenge 5: Pete the baker

Collapse
 
zerodragon profile image
Zero Dragon
const cakes = (recipe, available) => 
  Math.min(...Object.keys(recipe).map(ingredient =>
    Math.floor(available[ingredient] / recipe[ingredient]) || 0
  ))
console.log(cakes(
  {"flour": 500, "sugar": 200, "eggs": 1},
  {"flour": 1200, "sugar": 1200, "eggs": 5, "milk": 200}
)) // 2
Enter fullscreen mode Exit fullscreen mode