Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function goldMine(input) {
- let index = 0;
- let locations = Number(input[index]);
- index++;
- for (let i = 0; i < locations; i++) {
- let avgProfitGoal = Number(input[index]);
- index++;
- let days = Number(input[index]);
- index++;
- let profitSum = 0;
- for (let day = 0; day < days; day++) {
- let currentProfit = Number(input[index]);
- index++;
- profitSum += currentProfit;
- }
- let avgProfit = profitSum / days;
- if (avgProfit >= avgProfitGoal) {
- console.log(`Good job! Average gold per day: ${avgProfit.toFixed(2)}.`);
- } else {
- console.log(`You need ${(avgProfitGoal - avgProfit).toFixed(2)} gold.`);
- }
- }
- }
Add Comment
Please, Sign In to add comment