Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function dishWasher(input) {
- let broiButilkiPreparat = Number(input.shift());
- let totalPreparat = broiButilkiPreparat * 750;
- let totalDishes = 0;
- let totalPots = 0;
- let vhod = input.shift();
- let sudoveCount = Number(vhod);
- let counter = 1; //почва от 1, защото вкарваме съдове за миене още преди цикъла
- while (vhod != "End") {
- if (counter % 3 == 0) { //тенджери
- totalPreparat -= sudoveCount * 15;
- totalPots += sudoveCount;
- } else { //чинии
- totalPreparat -= sudoveCount * 5;
- totalDishes += sudoveCount;
- }
- if (totalPreparat < 0) { //ако след миенето на поредните съдове препарата е отрицателно число, направо излизаме от цикъла
- break;
- }
- vhod = input.shift();
- if (vhod != "End") {
- sudoveCount = Number(vhod);
- counter++; //щом входа е различен от End, значи ще започва още един цикъл със съдове за миене
- }
- }
- if (totalPreparat >= 0) { //ако препарата е бил достатъчен (>0) или е стигнал точно за всички чинии (=0)
- console.log("Detergent was enough!")
- console.log(`${totalDishes} dishes and ${totalPots} pots were washed.`)
- console.log(`Leftover detergent ${totalPreparat} ml.`)
- } else {
- console.log(`Not enough detergent, ${Math.abs(totalPreparat)} ml. more necessary!`)
- }
- }
- dishWasher(["2", "53", "65", "55", "End"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement