Why doesn't this pass?


  • 0
    D
    var arr = [];
    
    var addDigits = function change(num) {
        console.log('num '+num);
    	var sum = 0;
        arr = num.toString().split('');
    
        arr.forEach(function my(eachNum){
    	    eachNum = Number(eachNum);
    	    sum += eachNum;
        }); 
    
        if(sum<10) {
    	    console.log(sum);
    	    return sum;
        }
        
        num = sum;
    	change(num);
    };

  • 0
    S

    What if you alternate change(num) to return change(num)?


  • 0
    J

    because you forgot to tell it to return at the end

    num = sum;
    return change(num);


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.