Skip to content

Instantly share code, notes, and snippets.

@nedgrady
Created October 18, 2024 21:26
Show Gist options
  • Select an option

  • Save nedgrady/f94c157e422c3a984b40f8a8031785b4 to your computer and use it in GitHub Desktop.

Select an option

Save nedgrady/f94c157e422c3a984b40f8a8031785b4 to your computer and use it in GitHub Desktop.
function isPrime(num: number) {
if (num <= 1) return false;
for (let i = 2; i <= num; i++) {
if (num % i === 0) return false;
}
return true;
}
const numbers = [99999, 12, 15];
const allFactors = [];
for (let num of numbers) {
for (let i = 1; i <= num; i++) {
if (num % i === 0) allFactors.push(num);
}
}
const allPrimeFactors = allFactors.filter(isPrime);
console.log(allPrimeFactors);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment