Проблем със задачата 03. Inventory от 05. Programming Fundamentals Mid Exam
Здравейте, получвам 88/100 и не мога да разбера къде точно греша, някой може ли да ми помогне ?
Благодаря :)
задача : https://judge.softuni.org/Contests/Practice/Index/2028#2
код:
function solve(arr) {
let items = arr.shift().split(', ');
let command = arr.shift();
let actions = {Collect : collect, Drop:object => items = items.filter(x => x !== object),
"Combine Items" : combineItems, Renew : renew
}
function collect(object){
if(!items.includes(object)) items.push(object)
}
function combineItems(object){
let [oldItem, newItem] = object.split(':');
let index = items.findIndex(x => x === oldItem)
if(index >= 0){
items.splice(index + 1, 0, newItem);
}
}
function renew(object){
items = items.filter(x => x !== object);
items.push(object);
}
while (command !== 'Craft!') {
let [action, object] = command.split(' - ');
command = arr.shift()
actions[action](object)
}
console.log(items.join(", "))
}
Благодаря :)