Created
November 27, 2016 17:43
-
-
Save kungfux/cddbff8db1aee23893aa7766865270e1 to your computer and use it in GitHub Desktop.
Calculate sum of natural numbers
This file contains hidden or 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
| 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