Advertisement
miroLLL

Bo0oMB Numbers

Oct 18th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bombNumbers(sequence, bombInfo) {
  2.  
  3.     const bombNumber = bombInfo[0];
  4.     const bombPower = bombInfo[1];
  5.  
  6.     let bombIndex;
  7.  
  8.     while (((bombIndex = sequence.indexOf(bombNumber)) !== -1)) {
  9.  
  10.         sequence.splice(bombIndex + 1, bombPower); // Detonate right floated numbers
  11.  
  12.         let bombIndexV2 = (bombIndex - bombPower) >= 0 ? (bombIndex - bombPower) : 0;
  13.         let bombPowerV2 = (bombIndex - bombPower) >= 0 ? bombPower + 1 : bombIndex + 1;
  14.  
  15.         sequence.splice(bombIndexV2, bombPowerV2); // Detonate left floated numbers
  16.     }
  17.  
  18.     console.log(sequence.reduce((a, b) => a + b, 0))
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement