function isPrime(value) {
for(var i = 2; i < value; i++) {
if(value % i === 0) {
return false;
}
}
return true;
}
function genPrimeArr(num){
var arr = [];
for(var i=2; i<=num; i++){
if(isPrime(i)){
arr.push(i);
}
}
return arr;
}
function sumArr(arr){
var sum = 0;
for(var i=0; i<arr.length; i++){
sum += arr[i];
}
return sum;
}
function sumPrimes(num) {
return sumArr(genPrimeArr(num));
}
sumPrimes(10);
No comments:
Post a Comment