Skip to content

Instantly share code, notes, and snippets.

@ivan-demchenko
Last active January 4, 2016 11:09
Show Gist options
  • Save ivan-demchenko/8613819 to your computer and use it in GitHub Desktop.
Save ivan-demchenko/8613819 to your computer and use it in GitHub Desktop.
Prime numbers algorythm
function getPrimeNumbers(n) {
var arr = [];
for(var i = 2; i <= n; i++) {
for(var k = 2; k <= i; k++) {
if (i === k) arr.push(i);
if (i % k === 0) break;
}
}
return arr;
}
function getSumm(arr) {
return arr.reduce(function(p, c){
return p + c;
});
}
var primeNumebrs = getPrimeNumbers(100);
console.clear();
console.log('Prime numbers are: ' + primeNumebrs);
console.log('Summ is: ' + getSumm(primeNumebrs));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment