const primes = (num: number) => {
        let arr: Array<number> = Array.from({ length: num - 1 }).map((x, i) => i + 2),
          sqroot: number = Math.floor(Math.sqrt(num)),
          numsTillSqroot: Array<number> = Array.from({ length: sqroot - 1 }).map((x, i) => i + 2);
        numsTillSqroot.forEach(x => (arr = arr.filter(y => y % x !== 0 || y === x)));
        return arr;
      };
      

      Typescript language logoPrimes

      Codiga's TypeScript Recipes

      Generates primes up to a given number, using the Sieve of Eratosthenes.

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.