Last active
September 5, 2022 13:37
-
-
Save nickserv/c247e223a93c7cde51067cc6c79f7309 to your computer and use it in GitHub Desktop.
Permutations and combinations
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
function factorial(n) { | |
return n < 2 ? 1 : factorial(n - 1) * n; | |
} | |
function permutations(n, k) { | |
return factorial(n) / factorial(n - k) | |
} | |
function combinations(n, k) { | |
return factorial(n) / (factorial(k) * factorial(n - k)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment