-
-
Save IrhaAli/b0d300fcf1f71c441c73f3634b8c9142 to your computer and use it in GitHub Desktop.
Checks if the air is polluted given a threshold and a number of samples.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const checkAir = function (samples, threshold) { | |
//tallies the dirty samples | |
let pollution = 0; | |
for (let sample in samples){ | |
if (samples[sample] === 'dirty'){ | |
pollution++; | |
} | |
} | |
//checks if the total dirty samples exceed the threshold | |
if ((pollution /= samples.length) >= threshold){ | |
return 'Polluted'; | |
} else{ | |
return 'Clean'; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment