Skip to content

Instantly share code, notes, and snippets.

@cplpearce
Created August 8, 2020 02:32
Show Gist options
  • Save cplpearce/da1ffd86c8b4cd0fea07bd0945864245 to your computer and use it in GitHub Desktop.
Save cplpearce/da1ffd86c8b4cd0fea07bd0945864245 to your computer and use it in GitHub Desktop.
Kata 2 - Conditional sums
const conditionalSum = function(values, condition) {
let total = 0;
for (let val of values) {
if (condition === "even") {
val % 2 === 0 ? total += val : total += 0;
} else if (condition === "odd") {
val % 2 !== 0 ? total += val : total += 0;
} else {
continue;
}
}
return total;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment