Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function airPollution(areas, commands) {
- areas = areas.map(x => x.split(' ').map(Number));
- while (commands.length !== 0){
- let [com, arg] = commands.shift().split(' ');
- if (com === 'smog'){
- areas = areas.map(x => x.map(i => i + Number(arg)));
- } else {
- let index = Number(arg);
- if (com === 'breeze'){
- for (let row = 0; row < areas.length; row++) {
- let number = areas[index][row];
- areas[index][row] -= number < 15 ? number : 15;
- }
- } else if (com === 'gale'){
- for (let col = 0; col < areas.length; col++) {
- let number = areas[col][index];
- areas[col][index] -= number < 20 ? number : 20;
- }
- }
- }
- }
- let pollutedAreas = [];
- for (let i = 0; i < areas.length; i++) {
- for (let j = 0; j < areas[i].length; j++) {
- if (areas[i][j] >= 50){
- pollutedAreas.push(`[${i}-${j}]`);
- }
- }
- }
- if (pollutedAreas.length === 0){
- console.log('No polluted areas');
- } else {
- console.log(`Polluted areas: ${pollutedAreas.join(', ')}`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement