DEV Community

loading...

Discussion on: Daily Challenge #214 - Persistent Bugger

Collapse
aleksandrhovhannisyan profile image
Aleksandr Hovhannisyan

Recursive JavaScript solution:

function persistence(num) {
    const digits = `${num}`.split("");
    if (digits.length === 1) {
        return 0;
    }

    const product = digits.reduce((product, digit) => {
        return product * digit;
    }, 1);

    return 1 + persistence(product);
}