Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function bombNumbers(numberArea, specialNumber) {
- let bomb = specialNumber[0];
- let detonation = specialNumber[1];
- while (numberArea.includes(bomb)) {
- let bombIndex = numberArea.indexOf(bomb) - detonation;
- if (bombIndex < 0){
- bombIndex = 0;
- }
- let detonationArea = detonation * 2 + 1;
- numberArea.splice(bombIndex, detonationArea);
- }
- console.log(numberArea.reduce((a, b) => a + b, 0))
- }
- Или тарикатската:)
- function bombNumbers(numberArea, specialNumber) {
- while (numberArea.includes(specialNumber[0])) {
- let bombIndex = numberArea.indexOf(specialNumber[0]) - specialNumber[1];
- numberArea.splice(bombIndex < 0 ? 0 : bombIndex, specialNumber[1] * 2 + 1);
- }
- console.log(numberArea.reduce((a, b) => a + b, 0))
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement