Created
August 8, 2020 04:10
-
-
Save cplpearce/965f761ae0c86b18c7113c88c0e60abb to your computer and use it in GitHub Desktop.
Kata 7 - In the Air Tonight
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) { | |
let countDirty = 0; | |
for (let quality of samples) { | |
quality === "dirty" ? countDirty++ : null; | |
} | |
let ratio = countDirty / samples.length; | |
return (ratio > threshold ? "Polluted" : "Clean"); | |
}; | |
console.log(checkAir( | |
['clean', 'clean', 'dirty', 'clean', 'dirty', 'clean', 'clean', 'dirty', 'clean', 'dirty'], | |
0.3 | |
)); | |
console.log(checkAir( | |
['dirty', 'dirty', 'dirty', 'dirty', 'clean'], | |
0.25 | |
)); | |
console.log(checkAir( | |
['clean', 'dirty', 'clean', 'dirty', 'clean', 'dirty', 'clean'], | |
0.9 | |
)) | |
/* | |
Expected Output | |
Polluted | |
Polluted | |
Clean | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment