Number质数

const number = 180;

let arr = [];
let flag = true;

getPrime(number);

print(arr.join(' '));

function getPrime(num) {
    if (num === 1) {
        return null;
    }
   for (let i = 2; i <= num/i; i++) {
       if (Math.ceil(num/i) === num/i){
           arr.push(i);
           getPrime(num/i);
           flag = false;
           break;
       }
     }
    if (flag) {
        arr.push(num);
    }
}
  

  

上一篇:JavaScript学习


下一篇:攻防世界favorite_number