Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function santasGifts(input) {
- let cup = 140,
- bigSpoon = 20,
- smallSpoon = 10,
- cookiesPerBox = 5,
- singleCookieGrams = 25,
- totalBoxes = 0,
- batches = Number(input.shift());
- for (let b = 0; b < batches; b++) {
- let flour = Number(input.shift()),
- sugar = Number(input.shift()),
- cocoa = Number(input.shift());
- let flourCups = Math.floor(flour / cup),
- sugarSpoons = Math.floor(sugar / bigSpoon),
- cocoaSpoons = Math.floor(cocoa / smallSpoon);
- let boxesOfCookies = Math.floor((cup + bigSpoon + smallSpoon)
- * Math.min(flourCups, sugarSpoons, cocoaSpoons)
- / singleCookieGrams / cookiesPerBox);
- if (boxesOfCookies == 0) {
- console.log("Ingredients are not enough for a box of cookies.");
- } else {
- console.log(`Boxes of cookies: ${boxesOfCookies}`);
- totalBoxes += boxesOfCookies;
- }
- }
- console.log(`Total boxes: ${totalBoxes}`);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement