Advertisement
Spocoman

06. Bomb Numbers

Feb 8th, 2022 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bombNumbers(numberArea, specialNumber) {
  2.     let bomb = specialNumber[0];
  3.     let detonation = specialNumber[1];
  4.  
  5.     while (numberArea.includes(bomb)) {
  6.         let bombIndex = numberArea.indexOf(bomb) - detonation;
  7.         if (bombIndex < 0){
  8.             bombIndex = 0;
  9.         }
  10.         let detonationArea = detonation * 2 + 1;
  11.         numberArea.splice(bombIndex, detonationArea);
  12.     }
  13.    
  14.     console.log(numberArea.reduce((a, b) => a + b, 0))
  15. }
  16.  
  17. Или тарикатската:)
  18.  
  19. function bombNumbers(numberArea, specialNumber) {  
  20.     while (numberArea.includes(specialNumber[0])) {
  21.         let bombIndex = numberArea.indexOf(specialNumber[0]) - specialNumber[1];    
  22.         numberArea.splice(bombIndex < 0 ? 0 : bombIndex, specialNumber[1] * 2 + 1);
  23.     }
  24.     console.log(numberArea.reduce((a, b) => a + b, 0))
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement