Vacation от While Loop - Exercise с map()
Здравейте, опитвам се да реша задачата Vacation с map() но дава грешни отговори, някой може ли да ми помогне ?
Задача: https://judge.softuni.org/Contests/Compete/Index/2408#2
код:
function solve(input) {
let excursion = Number(input.shift())
let available = Number(input.shift())
let counter = 0;
input = input.map(x => {
let action = ""
let money = Number(x)
action === "spend" ? available -= money
: available += money
counter++
})
input < excursion ? console.log(`You can't save the money.\n${counter}`)
: console.log(`You saved the money for ${counter} days`)
}
Yes, I know, first reduce, now map() :))))) But for exercise purposes why not :))))
Anyway, thank you very much for the precious information :)