Skip to content

Instantly share code, notes, and snippets.

@IrhaAli
Created October 7, 2022 19:21
Show Gist options
  • Save IrhaAli/b0d300fcf1f71c441c73f3634b8c9142 to your computer and use it in GitHub Desktop.
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.
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