Recursive Digit Sum

  • + 0 comments

    Javascript Solution Easy Approach: Sum the individual N first then mult by K, instead of concate the N for K times.

    function superDigit(n, k) {
        if(n.toString().length == 1) return n;
        let p = n.toString().split("").reduce((a, b) => parseInt(a) + parseInt(b)) * k;
        return superDigit(p, 1);
    }