DEV Community

Discussion on: Daily Challenge #81 - Even or Odd

Collapse
 
savagepixie profile image
SavagePixie • Edited

Some JavaScript

const evenVsOdd = str => {
   const evens = str.split('').filter(x => x % 2 == 0).reduce((a, b) => a + parseInt(b), 0)
   const odds = str.split('').filter(x => x % 2 != 0).reduce((a, b) => a + parseInt(b), 0)

   return evens > odds ? "Even is greater than Odd"
      : evens == odds ? "Even and Odd are the same"
      : "Odd is greater than Even"
}