Skip to content

Instantly share code, notes, and snippets.

@NRKishanKumar
Last active February 23, 2024 08:48
Show Gist options
  • Save NRKishanKumar/942aab20fe69cbcf3119d607756d150c to your computer and use it in GitHub Desktop.
Save NRKishanKumar/942aab20fe69cbcf3119d607756d150c to your computer and use it in GitHub Desktop.
Find prime numbers in an array - Javascript
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