Created
November 23, 2016 03:00
-
-
Save elquimista/df8b245eaf0ae50a0685a0451b1524f5 to your computer and use it in GitHub Desktop.
Calculate combinations count in Javascript (ES5)
This file contains 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 combinationsCount(m, n) { | |
if (m < n) { | |
return 0; | |
} else if (m === n || n === 0) { | |
return 1; | |
} else { | |
var c = 1, i; | |
for (i = n + 1; i <= m; i ++) { | |
c *= i; | |
} | |
for (i = 2; i <= m - n; i ++) { | |
c /= i; | |
} | |
return c; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment