Advertisement
svetlio_top

Bomb Numbers

Feb 21st, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(arr, bomb){
  2.    
  3.     let arrIn = arr.slice(0);
  4.     let countRight=0;
  5.     let countLeft=0;
  6.    
  7.     for (let i = 0; i < arrIn.length; i++) {
  8.  
  9.         if (arrIn[i] === bomb[0]){
  10.            arrIn.splice(i,1);
  11.            while (i < arrIn.length) {
  12.                 arrIn.splice(i,1);
  13.                 countRight++;
  14.                 if(countRight === bomb[1]){  
  15.                     break;
  16.                 }
  17.             }
  18.             countRight=0;
  19.             for (let l = i-1; l >= 0; l--) {
  20.                 countLeft++;
  21.                 arrIn.splice(l,1);
  22.                 if(countLeft === bomb[1]){
  23.                     break;
  24.                 }
  25.             }
  26.             countLeft=0;
  27.      
  28.           i=0;
  29.         }
  30.  
  31.     }
  32.    
  33.     console.log(arrIn.reduce((a, b) => a + b, 0))
  34.  
  35. }
  36. solve([1, 2, 2, 4, 2, 2, 2, 9],
  37.     [4, 2]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement