Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve(arr, bomb){
- let arrIn = arr.slice(0);
- let countRight=0;
- let countLeft=0;
- for (let i = 0; i < arrIn.length; i++) {
- if (arrIn[i] === bomb[0]){
- arrIn.splice(i,1);
- while (i < arrIn.length) {
- arrIn.splice(i,1);
- countRight++;
- if(countRight === bomb[1]){
- break;
- }
- }
- countRight=0;
- for (let l = i-1; l >= 0; l--) {
- countLeft++;
- arrIn.splice(l,1);
- if(countLeft === bomb[1]){
- break;
- }
- }
- countLeft=0;
- i=0;
- }
- }
- console.log(arrIn.reduce((a, b) => a + b, 0))
- }
- solve([1, 2, 2, 4, 2, 2, 2, 9],
- [4, 2]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement