Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr) {
- arr = arr.map(Number);
- let neededPoints = arr.shift();
- let battles = arr.shift();
- let totalPoints = 0;
- let num = 0;
- for (let i = 0; i < battles; i++) {
- if (i % 3 === 0) {
- totalPoints += (arr[i] + arr[i] * 0.15);
- num++;
- } else if (i % 5 === 0) {
- totalPoints += (arr[i] - arr[i] * 0.1);
- num++;
- } else {
- totalPoints += arr[i];
- num++;
- }
- if (totalPoints >= neededPoints || totalPoints === neededPoints) {
- console.log(`Player successfully collected his needed experience for ${num} battles.`);
- return;
- }
- }
- console.log(`Player was not able to collect the needed experience, ${(neededPoints - totalPoints).toFixed(2)} more needed.`);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement