Skip to content

Instantly share code, notes, and snippets.

@kungfux
Created November 27, 2016 17:43
Show Gist options
  • Select an option

  • Save kungfux/cddbff8db1aee23893aa7766865270e1 to your computer and use it in GitHub Desktop.

Select an option

Save kungfux/cddbff8db1aee23893aa7766865270e1 to your computer and use it in GitHub Desktop.
Calculate sum of natural numbers
const sum = (n, a, b) => {
let result = 0;
for (let i = n - 1; i > 0; i--) {
if (i % a === 0 || i % b === 0) {
result += i;
}
}
return result;
}
export default sum;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment