DEV Community

Discussion on: Daily Challenge #173 - Pandemia

Collapse
 
ruanengelbrecht profile image
Ruan Engelbrecht

Late to the party. JavaScript.

const infectedPercentage = s => {
    let population = s.split('X');

    if (!population.some(x => x)) return '0';

    let infected = population
        .map(x => (x.includes('1') ? x.length : 0))
        .reduce((acc, v) => acc + v, 0);

    return `${(infected / population.join('').length) * 100}%`;
};