Simple function returning 'undefined' value

前端 未结 6 755
春和景丽
春和景丽 2020-12-28 19:28

This is the function I am currently working on:

function getSmallestDivisor(xVal) {    

    if (xVal % 2 === 0) {
        return 2;
    } else if (xVal % 3          


        
6条回答
  •  春和景丽
    2020-12-28 20:01

        if (xSqrt % 1 === 0) {
        // Because if your function walks this way 
        // it does not meet any 'return' statement
        // till the end and returns nothing. 
            getSmallestDivisor(xSqrt);
        } else {
            return xVal;
        }
    

提交回复
热议问题