Created
October 18, 2024 21:28
-
-
Save nedgrady/d6fe1a27b46ec5e366048e01daaa0617 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(numberToCheck: number) { | |
| if (numberToCheck <= 1) return false; | |
| for (let possibleDivisor = 2; possibleDivisor <= numberToCheck; possibleDivisor++) { | |
| if (numberToCheck % possibleDivisor === 0) return false; | |
| } | |
| return true; | |
| } | |
| const numbers = [99999, 12, 15]; | |
| const allFactors = []; | |
| for (let numberToFactorise of numbers) { | |
| for (let possibleFactor = 1; possibleFactor <= numberToFactorise; possibleFactor++) { | |
| if (numberToFactorise % possibleFactor === 0) allFactors.push(numberToFactorise); | |
| } | |
| } | |
| 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