Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function goldMine(input) {
- let index = 0;
- let locations = Number(input[index++]);
- for (let i = 0; i < locations; i++) {
- let averageGold = Number(input[index++]);
- let dayDigging = Number(input[index++]);
- let goldSum = 0;
- for (let j = 0; j < dayDigging; j++) {
- goldSum += Number(input[index++]);
- }
- if ((goldSum / dayDigging) >= averageGold) {
- console.log(`Good job! Average gold per day: ${(goldSum / dayDigging).toFixed(2)}.`)
- } else {
- console.log(`You need ${(averageGold - (goldSum / dayDigging)).toFixed(2)} gold.`)
- }
- }
- }
- Решение със shift():
- function goldMine(input) {
- let locations = Number(input.shift());
- for ( let i = 0; i < locations; i++) {
- let averageGold = Number(input.shift());
- let dayDigging = Number(input.shift());
- let goldSum = 0;
- for (let j = 0; j < dayDigging; j++) {
- goldSum += Number(input.shift());
- }
- if ((goldSum / dayDigging) >= averageGold) {
- console.log(`Good job! Average gold per day: ${(goldSum / dayDigging).toFixed(2)}.`)
- } else {
- console.log(`You need ${(averageGold - (goldSum / dayDigging)).toFixed(2)} gold.`)
- }
- }
- }
Add Comment
Please, Sign In to add comment