DEV Community

Discussion on: Daily Challenge #173 - Pandemia

Collapse
jehielmartinez profile image
Jehiel Martinez

In Javascript

function doomPercentage(s) {
    let infected = 0;
    let total = 0;

    if(!s.includes('1') || !s.includes('0')){
        return 0;
    }

    s.split('X').forEach(continent => {
        if(continent.includes('1')){          
            continent = continent.replace(/0/gi, '1');
            infected += continent.length;
        }
        total += continent.length
    });

    return 100*infected/total;
};


`

Collapse
nijeesh4all profile image
Nijeesh Joshy

nice function name :D