Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function cs(input){
- let arr=input.slice();
- let initialEnergy=arr.shift();
- let winCount=0;
- for (const commands of arr) {
- if(commands!=="End of battle"){
- let energy=Number(commands);
- if(initialEnergy-energy<0){
- console.log(`Not enough energy! Game ends with ${winCount} won battles and ${initialEnergy} energy`);
- return;
- }
- initialEnergy-=energy;
- winCount++
- }else {
- console.log(`Won battles: ${winCount}. Energy left: ${initialEnergy}`);
- }
- if(winCount%3==0){
- initialEnergy+=winCount;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement