Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function pollution(input, forces) {
- let map = [];
- for (let i = 0; i < input.length; i++) {
- map.push(input[i].split(' ').map(Number));
- }
- function setBreeze(map, index) {
- for (let i = 0; i < map.length; i++) {
- map[index][i] -= 15;
- if (map[index][i] < 0) {
- map[index][i] = 0;
- }
- }
- }
- function setGale(map, index) {
- for (let i = 0; i < map.length; i++) {
- map[i][index] -= 20;
- if (map[i][index] < 0) {
- map[i][index] = 0;
- }
- }
- }
- function setSmog(map, index) {
- for (let i = 0; i < map.length; i++) {
- for (let j = 0; j < map[i].length; j++) {
- map[i][j] += index;
- }
- }
- }
- for (let i = 0; i < forces.length; i++) {
- let tokens = forces[i].split(' ');
- let currentForce = tokens[0];
- let index = Number(tokens[1]);
- switch (currentForce) {
- case 'breeze':
- setBreeze(map, index);
- break;
- case 'gale':
- setGale(map, index);
- break;
- case 'smog':
- setSmog(map, index);
- break;
- }
- }
- if (map.some(x => x.some(y => y >= 50))) {
- let polluted = [];
- for (let i = 0; i < map.length; i++) {
- for (let j = 0; j < map[i].length; j++) {
- if (map[i][j] >= 50) {
- polluted.push(`[${i}-${j}]`);
- }
- }
- }
- console.log(`Polluted areas: ${polluted.join(', ')}`);
- }
- else {
- console.log('No polluted areas');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement