SHARE
TWEET

Untitled

a guest Jun 20th, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input) {
  2.     let budget = Number(input.shift());
  3.     let command = input.shift();
  4.  
  5.     let moneySum = 0;
  6.     let bonus = 0;
  7.     let leftMoney = 0;
  8.  
  9.     while (budget > moneySum) {
  10.         let name = command;
  11.         let money = Number(input.shift());
  12.        
  13.         if (name.length > 15) {
  14.             bonus = leftMoney * 0.2;
  15.         }
  16.         moneySum += money + bonus;
  17.         bonus = 0;
  18.  
  19.        
  20.         leftMoney = budget - moneySum;
  21.  
  22.         command = input.shift();
  23.         if (command == "ACTION") {
  24.             break;
  25.         }
  26.        
  27.     }
  28.     let diff = Math.abs(budget - moneySum);
  29.  
  30.     if (budget >= moneySum) {
  31.         console.log(`We are left with ${diff.toFixed(2)} leva.`)
  32.     }
  33.     else {
  34.         console.log(`We need ${diff.toFixed(2)} leva for our actors.`)
  35.     }
  36. }
  37.  
  38. solve([90000, "Christian Bale", 70000.50, "Leonard DiCaprio Kevin Spacey", 24000.99, "ACTION"])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top