Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(sequence, sbnAndPower) {
- let sequenceOfNum = sequence;
- let specialBombNumber = sbnAndPower[0];
- let bombPower = sbnAndPower[1]
- let sum = 0;
- for (let i = 0; i < sequenceOfNum.length; i++) {
- if (specialBombNumber === sequenceOfNum[i]) {
- /* for (let j = i - bombPower; j <= i + bombPower; j++)
- sequenceOfNum[j] = 0 */
- let index = i - bombPower
- let index2 = bombPower * 2 + 1
- if (index < 0) {
- index = 0
- index2 -= Math.abs(i - bombPower)
- }
- sequenceOfNum.splice(index, index2, 0);
- }
- }
- /* len = sequenceOfNum.length
- for (let i = 0; i < len; i++) {
- if (specialBombNumber === sequenceOfNum[i]) {
- sequenceOfNum.splice(i, bombPower + 1, 0);
- }
- } */
- for (let el of sequenceOfNum) {
- sum += el;
- }
- console.log(sum)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement