03. Heart Delivery - 80/100
Здравейте,
Може ли насоки за тази задача стигнах 80/100 и не мога да намеря останалите грешки.
https://judge.softuni.org/Contests/Practice/Index/2031#2
Това е кода
function heartDelivery(arrOfElements) {
let neighborhood = arrOfElements.shift().split("@").map(Number);
let actions = arrOfElements.shift().split(" ");
let currentCommand = actions.shift();
let previousIndex = 0;
while (currentCommand !== "Love!") {
let jumpIndex = Number(actions.shift());
jumpIndex += previousIndex;
if (jumpIndex >= neighborhood.length || jumpIndex < 0) {
jumpIndex = 0;
}
if (neighborhood[jumpIndex] !== 0) {
neighborhood[jumpIndex] -= 2;
if (neighborhood[jumpIndex] <= 0) {
console.log(`Place ${jumpIndex} has Valentine's day.`);
}
} else {
console.log(`Place ${jumpIndex} already had Valentine's day.`);
}
previousIndex = jumpIndex;
actions = arrOfElements.shift().split(" ");
currentCommand = actions.shift();
}
let failedPlaces = neighborhood.filter((x) => x !== 0);
let successPlaces = neighborhood.filter((y) => y === 0);
if (successPlaces.length === neighborhood.length <= 0) {
return console.log(`Mission was successful.`);
} else {
console.log(`Cupid's last position was ${previousIndex}.`);
console.log(`Cupid has failed ${failedPlaces.length} places.`);
}
}
Благодаря!