Created
December 9, 2019 22:22
-
-
Save gavinsykes/532e9dd88b7d77c6e15cda7df7fa8053 to your computer and use it in GitHub Desktop.
Project Euler Problem 15 in JavaScript
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 euler_15 = n => nCr(2*n,n); | |
const nCr = (n,r) => { | |
if (r > n || n < 1 || r < 1) { | |
return undefined; | |
} | |
return factorial(n) / (factorial(r) * factorial(n-r)); | |
}; | |
const factorial = num => { | |
let result = 1, | |
n = +num; | |
while (n > 1) { | |
n--; | |
result *= n; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment