Here you can find the source of sumPrimes(num)
/* Intermediate Algorithm: Sum All Primes Sum all the prime numbers up to and including the provided number. A prime number is defined as a number greater than one and having only two divisors, one and itself. For example, 2 is a prime number because it's only divisible by one and two./*w w w.ja v a2 s .c om*/ The provided number may not be a prime. Remember to use Read-Search-Ask if you get stuck. Write your own code. Here are some helpful hints: For Loops Array.prototype.push() Written by: Sean M Hamlet https://www.freecodecamp.com/seanmhamlet */ function sumPrimes(num) { // Remember one isn't a prime so start prime check loops at 2 function isPrime(number) { for (var i = 2; i < number; i++) { if (number % i === 0) { return false; } } return true; } // Start prime number sum at 0 var sum = 0; // Loop through all numbers up to and including the number for (var j = 2; j <= num; j++) { if (isPrime(j)) { sum += j; } } return sum; } sumPrimes(10);
"use strict"; Number.prototype.primeFactors = function() { var v, i; v = null; for (i = 2; i < this - 1; i += 1) { if (this % i === 0) { v = i; break; if (v) { return [v].concat(Math.floor(this / v).primeFactors()); } else { return [this]; }; console.log(Math.max.apply(null, (600851475143).primeFactors()));
"use strict"; var i, j, triangleNumber; Number.prototype.primeFactors = function() { var v, i; v = null; for (i = 2; i < this - 1; i += 1) { if (this % i === 0) { v = i; break; ...
Number.prototype.primeFactors = function() { var number = this.valueOf(); var primeFactors = []; isPrime = function(primeCandidate) { var p = 2; var top = Math.floor(Math.sqrt(primeCandidate)); while(p<=top){ if(primeCandidate%p === 0){ return false; } p++; ...
"use strict"; var i, primeFactorLists; Number.prototype.primeFactors = function() { var v, i; v = null; for (i = 2; i < this - 1; i += 1) { if (this % i === 0) { v = i; break; ...
function sumPrimes(num) { var primes = []; for (var i = 2; i <= num; i++) { var notPrime = false; for (var current = 2; current <= (i - 1); current++) { if (i % current === 0) { notPrime = true; if (notPrime === false) primes.push(i); var sum = primes.reduce(function(pv, cv) { return pv + cv; }); return sum; sumPrimes(10);