Advertisement
dabidabidesh

bomb splice

Jun 22nd, 2020
3,069
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(sequence, sbnAndPower) {
  2.  
  3.   let sequenceOfNum = sequence;
  4.   let specialBombNumber = sbnAndPower[0];
  5.   let bombPower = sbnAndPower[1]
  6.  
  7.   let sum = 0;
  8.  
  9.   for (let i = 0; i < sequenceOfNum.length; i++) {
  10.     if (specialBombNumber === sequenceOfNum[i]) {
  11.       /* for (let j = i - bombPower; j <= i + bombPower; j++)
  12.         sequenceOfNum[j] = 0 */
  13.       let index = i - bombPower
  14.       let index2 = bombPower * 2 + 1
  15.       if (index < 0) {
  16.         index = 0
  17.         index2 -= Math.abs(i - bombPower)
  18.       }
  19.  
  20.       sequenceOfNum.splice(index, index2, 0);
  21.     }
  22.   }
  23.  
  24.   /* len = sequenceOfNum.length
  25.  
  26.   for (let i = 0; i < len; i++) {
  27.     if (specialBombNumber === sequenceOfNum[i]) {
  28.       sequenceOfNum.splice(i, bombPower + 1, 0);
  29.     }
  30.   } */
  31.  
  32.   for (let el of sequenceOfNum) {
  33.     sum += el;
  34.   }
  35.   console.log(sum)
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement