In my code, if i enter parameter as 10, then i pass all tests. But as soon as i pass 73156, the page stops responding.
I don’t understand why this is happening, cuz all nos are passed for testing.
function sumPrimes(num) {
var primeArr = [];
for(var i = num; i > 1; i--) {
var sqrt = Math.ceil(Math.sqrt(i));
var numsBelow = Array.from({length:sqrt}, (v,i) => i+2);
var isNotPrime = numsBelow.some(num => {
if(i !== num){
return i % num === 0;
}
return false;
});
console.log(i, numsBelow, isNotPrime);
if(!isNotPrime) primeArr.push(i);
}
return primeArr.reduce((total, current) => total + current);
}
sumPrimes(73156);