const primeFactors = (n: number) => {
        let a: Array<number> = [],
          f = 2;
        while (n > 1) {
          if (n % f === 0) {
            a.push(f);
            n /= f;
          } else {
            f++;
          }
        }
        return a;
      };
      
      Typescript language logo

      Prime factors

      Codiga's TypeScript Recipes

      Finds the prime factors of a given number using the trial division algorithm.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.