Skip to content

Instantly share code, notes, and snippets.

@bajoski34
Created January 11, 2022 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bajoski34/496e3b1757cb91f70bd22b02190aa425 to your computer and use it in GitHub Desktop.
Save bajoski34/496e3b1757cb91f70bd22b02190aa425 to your computer and use it in GitHub Desktop.
//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