25 lines
547 B
JavaScript
25 lines
547 B
JavaScript
/*
|
|
https://projecteuler.net/problem=1
|
|
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9.
|
|
The sum of these multiples is 23.
|
|
|
|
Find the sum of all the multiples of 3 or 5 below 1000.
|
|
*/
|
|
|
|
var isMultipleOf = (m) => (n) => n % m === 0;
|
|
var is3_ = isMultipleOf(3);
|
|
var is5_ = isMultipleOf(5);
|
|
|
|
var is3 = (n) => n % 3 === 0;
|
|
var is5 = (n) => n % 5 === 0;
|
|
|
|
var limit = 1000;
|
|
let result = 0;
|
|
for (let i = 0; i < limit; i++) {
|
|
if (is3(i) || is5(i)) {
|
|
result += i;
|
|
}
|
|
}
|
|
|
|
console.log(`Answer is ${result}`);
|