Advertisement
teofarov13

Untitled

Feb 11th, 2023
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function bombNums(sequence, bombNum) {
  2.     /**
  3. * Write a function that receives two parameters: sequence of numbers and special bomb number
  4.  with a certain power.
  5. Your task is to detonate every occurrence of the special bomb number and according to
  6. its power his neighbors from left and right. Detonations are performed from left to
  7.  right and all detonated numbers disappear.
  8. The input contains two arrays of numbers. The first contains the initial sequence and the second contains the special bomb number and its power.
  9. The output is the sum of the remaining elements in the sequence.*/
  10.  
  11.     for (let i = 0; i < sequence.length; i++) {
  12.       // if (sequence[i] === bombNum[0]) {
  13.         let firstHalf = sequence
  14.             .splice(0, bombNum[0])
  15.             .sort((a, b) => b - a)
  16.         let radius = bombNum[1];
  17.         let explosionRadius=firstHalf.splice(0,radius)
  18.  
  19.        //}
  20.     }
  21.     let firstHalf = sequence
  22.             .splice(0, bombNum[0])
  23.             .sort((a, b) => b - a)
  24.         let radius = bombNum[1];
  25.         let explosionRadius=firstHalf.splice(0,radius)
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement