Created
August 8, 2020 02:32
-
-
Save cplpearce/da1ffd86c8b4cd0fea07bd0945864245 to your computer and use it in GitHub Desktop.
Kata 2 - Conditional sums
This file contains hidden or 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 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