The sum of the first 100 numbers:
const sum = _.chain(_.range(1, 101)) .reduce((memo, val) => memo + val, 0) .value(); document.write(sum);
The sum of the first 100 primes:
function isPrime(number) {
var start = 2;
while (start <= Math.sqrt(number)) {
if (number % start++ < 1) return false;
}
return number > 1;
}
const sum2 = _.chain(_.range(1, 100000)) // what should stop be?
.filter(isPrime)
.first(100)
.reduce((memo, val) => memo + val, 0)
.value();
document.write(sum2);