← Back to challenges

Odds vs. Evens

JavaScriptHardlanguage_fundamentalsmath

Instructions

Given an integer, return "odd" if the sum of all odd digits is greater than the sum of all even digits. Return "even" if the sum of even digits is greater than the sum of odd digits, and "equal" if both sums are the same.

Examples

oddsVsEvens(97428) ➞ "odd"
// odd = 16 (9+7)
// even = 14 (4+2+8)

oddsVsEvens(81961) ➞ "even"
// odd = 11 (1+9+1)
// even = 14 (8+6)

oddsVsEvens(54870) ➞ "equal"
// odd = 12 (5+7)
// even = 12 (4+8+0)

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Construct and Deconstruct