LoginSignup
9
3

More than 5 years have passed since last update.

整数numの約数を一覧とその数。

Last updated at Posted at 2015-11-12
function divisor(num){
    var results = [];
    for(var i=1; i<=num; i++) {
        if( (num%i == 0) ) {
            results.push(i);
        }
    }
    return results;
}

// テスト
r = divisor(1024);
console.log(r);
// [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024]

consooe.log(r.length);
// 11

9
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
3