Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function massacre(arr) {
- let bunnyBombs = arr.pop()
- .split(" ")
- .map(element => element.split(",")
- .map(Number));
- let field = arr.map(row => row.split(' ')
- .map(Number));
- let snowRamboDemmage = 0;
- let bunnyesMassacred = 0;
- // Dealing dammage for each bombbunny + addind bomb bunny bomb power
- bunnyBombs.forEach(bunny => {
- let row = bunny[0];
- let col = bunny[1];
- // Defining bomb bunnie bomb power
- bombBunny = field[col][row];
- //dealing dammage by rows + check for KIA bomb bunnies (bombed bombs)
- if (bombBunny > 0) {
- snowRamboDemmage += bombBunny;
- bunnyesMassacred += 1;
- // Checking positions around the bomb
- for (let i = row - 1; i <= row + 1; i++) {
- for (let j = col - 1; j <= col + 1; j++) {
- // Check if the position is outside the board
- if (j >= 0 && i >= 0 && j <= field.length - 1 && i <= field[0].length) {
- field[i][j] = field[i][j] - bombBunny;
- if (field[i][j] < 0) {
- field[i][j] = 0;
- }
- }
- }
- }
- }
- });
- // Killing the bunnies that susvived IIWW
- field.forEach(row => {
- for (const cell in row) {
- if (row[cell] > 0) {
- bunnyesMassacred++;
- snowRamboDemmage += row[cell];
- }
- }
- });
- console.log(snowRamboDemmage)
- console.log(bunnyesMassacred)
- }
- massacre(
- ['5 10 15 20',
- '10 10 10 10',
- '10 15 10 10',
- '10 10 10 10',
- '2,2 0,1']
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement