Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function movingTarget(input) {
- let targets = input.shift().split(' ').map(Number);
- [command, index, value] = input.shift().split(' ');
- while (command != "End") {
- index = Number(index);
- value = Number(value);
- if (command === "Shoot") {
- if (index >= 0 && index < targets.length) {
- targets[index] -= value;
- if (targets[index] <= 0) {
- targets.splice(index, 1);
- }
- }
- } else if (command === "Add") {
- if (index >= 0 && index < targets.length) {
- targets.splice(index, 0, value);
- } else {
- console.log("Invalid placement!");
- }
- } else if (command === "Strike") {
- if (index - value >= 0 && index + value < targets.length) {
- targets.splice(index - value, value * 2 + 1);
- } else {
- console.log("Strike missed!");
- }
- }
- [command, index, value] = input.shift().split(' ');
- }
- console.log(targets.join('|'));
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement