了解Factorialize解决方案

时间:2016-05-09 17:21:44

标签: javascript algorithm

function factorialize(num) {
    var count = 1;
    for (var i = 1; i < num; i++) {
        count = count + (count * i);
    }
    return count;
}

factorialize(1);

为什么在使用1时会返回1?不应该返回2因为count = 1 +(1 * 1)?

1 个答案:

答案 0 :(得分:0)

对于Intent goToHomeIntent = new Intent(Intent.ACTION_MAIN); goToHomeIntent.addCategory(Intent.CATEGORY_HOME); goToHomeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(goToHomeIntent); ,当我们进入循环时,支票num = 1返回false,因此我们无法进入i < num并以count = 1转到count = count + (count * i);