AreWe

Counter Strike kozmoza

Jun 18th, 2020
1,883
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr) {
  2.  
  3.     let initialEnergy = arr.shift();
  4.     let currentEnergy = Number(initialEnergy);
  5.  
  6.     let counter = 0;
  7.  
  8.     for (let command of arr) {
  9.         let distance = command;
  10.         if (command === "End of battle") {
  11.             console.log(`Won battles: ${counter}. Energy left: ${currentEnergy}`)
  12.             break;
  13.         }
  14.         distance = Number(command);
  15.  
  16.         if (currentEnergy - distance < 0) {
  17.             console.log(`Not enough energy! Game ends with ${counter} won battles and ${currentEnergy} energy`);
  18.             break;
  19.         }
  20.         currentEnergy -= Number(distance);
  21.         counter++;
  22.         if (counter % 3 == 0) {
  23.             currentEnergy += counter;
  24.         }
  25.     }
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment