Skip to content

Instantly share code, notes, and snippets.

@nickserv
Last active September 5, 2022 13:37
Show Gist options
  • Save nickserv/c247e223a93c7cde51067cc6c79f7309 to your computer and use it in GitHub Desktop.
Save nickserv/c247e223a93c7cde51067cc6c79f7309 to your computer and use it in GitHub Desktop.
Permutations and combinations
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