Last active
February 23, 2024 08:48
-
-
Save NRKishanKumar/942aab20fe69cbcf3119d607756d150c to your computer and use it in GitHub Desktop.
Find prime numbers in an array - Javascript
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
var a = [5, 9, 63, 29, 35, 6, 55, 23] | |
var prime = []; | |
function isPrime(item) { | |
var identifier = item / 2; | |
for (var j = 2; j <= identifier; j++) { | |
if ((item % j) == 0) { // modulous | |
return false; | |
} | |
} | |
return true; | |
} | |
for (var index = 0; index < a.length; index++) { | |
if (isPrime(a[index])) { | |
prime.push(a[index]) | |
} | |
} | |
console.log(prime); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment