DEV Community

Discussion on: Daily Challenge #173 - Pandemia

Collapse
 
savagepixie profile image
SavagePixie • Edited

JavaScript:

const getInfected = str => {
   const pop = str
      .replace(/[^10X]/g, '')
      .split('X')
      .reduce(
         (a, b) => b.includes('1')
         ? { infected: a.infected + b.length, total: a.total + b.length
         : { ...a, total: a.total + b.length }
      , { infected: 0, total: 0})
   return `${pop.infected / pop.total * 100}℅`
}