Javascript: find first n prime numbers
Posted
by
bard
on Stack Overflow
See other posts from Stack Overflow
or by bard
Published on 2013-06-29T16:12:28Z
Indexed on
2013/06/29
16:21 UTC
Read the original article
Hit count: 218
JavaScript
function primeNumbers() {
array = [];
for (var i = 2; array.length < 100; i++) {
for (var count = 2; count < i; count++) {
var divisorFound = false;
if (i % count === 0) {
divisorFound = true;
break;
}
}
if (divisorFound == false) {array.push[i];}
}
return array;
}
When I run this code, it seems to get stuck in an infinite loop and doesn't return anything... why?
© Stack Overflow or respective owner