+ Нов въпрос
stamcheva 0 Точки

## Здравейте, конзолата ми дава targets.split is not a function, а judge му дава 50/100. Може ли някой да ми помогне?

function shoot(input){

let targets = input.shift()

targets = targets.split(" ")

targets = targets.map(x => Number(x));

input.pop();

let shots = input.map(x => Number(x))

let numberOfShots = 0;

for (let i = 0; i < shots.length; i++) {

let currentShot = shots[i];

let currentTarget = targets[currentShot];

if (currentTarget > -1) {

targets[currentShot] = -1;

numberOfShots++;

for (let j = 0; j < targets.length; j++) {

if (targets[j] > -1) {

if (targets[j > currentTarget]) {

targets[j] -= currentTarget;

} else {

targets[j] += currentTarget;

}

}

}

}

console.log(`Shot targets: \${numberOfShots} -> \${targets.join(' ')}`)

}

}

Тагове:
0
Axiomatik 1581 Точки

Shoot for the Win ?

;-)

``````function shoot(input) {
let targets = input.shift();

targets = targets.split(" ").map(x => Number(x));
// targets = targets.map(x => Number(x));

// input.pop();

// let shots = input.map(x => Number(x))

let numberOfShots = 0;
let command = input.shift();

while (command !== 'End') {
const index = Number(command);
if (index < 0 || index >= targets.length || targets[index] === -1) {
command = input.shift();
continue;
}

const currentTargetNumber = targets[index];
targets[index] = -1;
numberOfShots++;

for (let i = 0; i < targets.length; i++) {
if (targets[i] === -1) {
continue;
}

if (targets[i] > currentTargetNumber) {
targets[i] -= currentTargetNumber;
} else {
targets[i] += currentTargetNumber;
}
}

command = input.shift();
}

// for (let i = 0; i < shots.length; i++) {

//     let currentShot = shots[i];

//     let currentTarget = targets[currentShot];

//     if (currentTarget > -1) {

//         targets[currentShot] = -1;

//         numberOfShots++;

//         for (let j = 0; j < targets.length; j++) {

//             if (targets[j] > -1) {

//                 if (targets[j > currentTarget]) {

//                     targets[j] -= currentTarget;

//                 } else {

//                     targets[j] += currentTarget;

//                 }

//             }

//         }
//     }
// }

console.log(`Shot targets: \${numberOfShots} -> \${targets.join(' ')}`)
}``````

0