Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(inputArrTargets, inputArrBomb) {
- let [bomb, blast] = inputArrBomb;
- let targets = inputArrTargets;
- let sum = targets.reduce((a, b) => a + b);
- if (blast < 0) {
- blast = 0;
- }
- for (i = 0; i < targets.length; i++) {
- if (targets[i] === bomb && i - blast < 0) {
- if (blast > targets.length) {
- sum = 0;
- } else {
- sum = 0;
- targets.splice(0, (blast * 2 + 1) + (i - blast));
- for (j = 0; j < targets.length; j++) {
- sum += targets[j];
- }
- i = 0;
- }
- } else if (targets[i] === bomb && i + blast < targets.length) {
- if (blast > targets.length) {
- sum = 0;
- } else {
- sum = 0;
- targets.splice(i - blast, blast * 2 + 1);
- for (j = 0; j < targets.length; j++) {
- sum += targets[j];
- }
- i = 0;
- }
- } else if (targets[i] === bomb && i + blast >= targets.length) {
- if (blast > targets.length) {
- sum = 0;
- } else {
- sum = 0;
- targets.splice(i - blast);
- for (j = 0; j < targets.length; j++) {
- sum += targets[j];
- }
- i = 0;
- }
- }
- }
- console.log(sum);
- }
Advertisement
Add Comment
Please, Sign In to add comment