Hey, everything went nearly smooth, till last few challenges im dealing with.
function sumPrimes(num) {
var numbers = [];
for (var i = 2; i <= num; i++) {
if (isPrimeNumber(i)) {
numbers.push(i);
}
}
return numbers.reduce(function(a, b) {
return a + b;
});
}
function isPrimeNumber(num) {
for (var x = 2; x < num; x++) {
if(num % x === 0) {
return false;
}
}
return true;
}
sumPrimes(10);
Can anyone PLEASE explain the logic behind this? how those two function match each other? how the loop passes results…I really dont get this one