проблем с 02. Treasure Hunt от 06. Programming Fundamentals Mid Exam Retake
Здравейте, получавам 10/100 и не знам как да оправя грешките, някой може ли да ми помогне ?
Благодаря :)
задача: https://judge.softuni.org/Contests/Practice/Index/1773#1
код:
function solve(input){
let state = input.shift().split("|")
let actions = {
"Loot": loot, "Drop": drop, "Steal": steal
}
function loot(items){
items.forEach(x => {
if(!state.includes(x)) state.unshift(x)
})
}
function drop(index){
let item = state[index]
if(state[index] !== undefined)
state.splice(item, 1)
state.push(item)
}
function steal(count){
let items = state.splice(-count)
console.log(items.join(", "))
}
input.forEach(x => {
if(x !== "Yohoho!"){
const [a, b] = x.split(" ").map(x => (isNaN(x) ? x : Number(x)))
try{
actions[a](b)
}catch(e){
}
}
})
let avg = state.reduce((a, v) => a + v.length, 0) / state.length
state.length === 0 ? console.log("Failed treasure hunt.")
: console.log(`Average treasure gain: ${avg.toFixed(2)} pirate credits.`)
}
I saw the mistake and now I have 100/100
Thanks a lot !
You've got the solution in front of you, no one will help you during the exams and the exams will get more and more difficult with each further level (dito when you land a job at a software company - no senior will be around to help you out) !!!
JS discussions =>
Java discussions =>