Skip to content

Instantly share code, notes, and snippets.

@cplpearce
Created August 8, 2020 04:10
Show Gist options
  • Save cplpearce/965f761ae0c86b18c7113c88c0e60abb to your computer and use it in GitHub Desktop.
Save cplpearce/965f761ae0c86b18c7113c88c0e60abb to your computer and use it in GitHub Desktop.
Kata 7 - In the Air Tonight
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