Created
October 18, 2024 21:26
-
-
Save nedgrady/f94c157e422c3a984b40f8a8031785b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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