Created
January 11, 2022 15:42
-
-
Save bajoski34/496e3b1757cb91f70bd22b02190aa425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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. | |
const solution = (a,b, K) => { | |
let N = Array(K); | |
let length = N.length; | |
let multiples = []; | |
for( i = 0; i < length; i++ ){ | |
if( i % a === 0 || i % b === 0 ){ | |
multiples.push(i); | |
} | |
} | |
return multiples.reduce( (a,b) => a + b, 0); | |
} | |
console.log(solution(3,5,1000))// returns the sum of multiples of 3 and 5 from 1 to 1000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment