Trying to find factors of a number in JS

前端 未结 13 2806
陌清茗
陌清茗 2021-02-19 04:52

I am just starting JS, and understand the concept of finding a factor. However, this snippet of code is what I have so far. I have the str variable that outputs nothing but the

13条回答
  •  梦谈多话
    2021-02-19 05:22

    function primeFactors(n) {
      let arrPrime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79];
      let divisor = 2,
        divided = n,
        arr = [],
        count = 0, out = "";
      while (divisor < n) {
        if (divided % divisor == 0) {
          arr.push(divisor)
          divided /= divisor;
          console.log(divisor);
        }
        else {
          divisor++;
        }
      }
      console.log(count);
      // let news = arr.filter(num => num != ",")
      // console.log(news);
      // arr.slice(indexOf(map(",")), 1)
      return arr;
    }
    
    let out = primeFactors(86240);
    console.log(out);

提交回复
热议问题