Created
February 1, 2022 16:07
-
-
Save floydpink/d2edeba5142e2181d2985b060f9c0952 to your computer and use it in GitHub Desktop.
Find Prime Numbers
This file contains 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
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]; | |
const isPrime = (num: number) => { | |
const sqRoot = Math.floor(Math.sqrt(num)); | |
let prime = num != 1; | |
for (let i = 2; i < sqRoot + 1; i++) { | |
if (num % i == 0) { | |
prime = false; | |
break; | |
} | |
} | |
return prime; | |
}; | |
const result = numbers.filter((cr) => isPrime(cr)); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment