• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# PB April - Vacation Problem

miroLLL May 17th, 2020 791 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function solution(inputData) {
2.
3.     let vacationExpenses = Number(inputData[0]);
4.     let amount = Number(inputData[1]);
5.
6.     let index = 2;
7.     let days = 0;
8.     let spendMoneyDays = 0;
9.
10.     let currentAction = inputData[index];
11.     let currentAmount = Number(inputData[index + 1]);
12.
13.     while ((currentAction !== undefined) && (spendMoneyDays < 5)) {
14.
15.         if (currentAction === 'spend') {
16.             amount = Math.max((amount - currentAmount), 0);
17.             spendMoneyDays++;
18.         } else if (currentAction === 'save') {
19.             amount += currentAmount;
20.             spendMoneyDays = 0;
21.         }
22.
23.         index += 2;
24.         days++;
25.
26.         currentAction = inputData[index];
27.         currentAmount = inputData[index + 1];
28.     }
29.
30.     if (spendMoneyDays >= 5) {
31.         console.log("You can't save the money.");
32.         console.log(`\${days}`);
33.
34.     } else if (amount >= vacationExpenses) {
35.
36.         console.log(`You saved the money for \${days} days.`);
37.     }
38. }
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.
Top