Skip to content

Instantly share code, notes, and snippets.

@elquimista
Created November 23, 2016 03:00
Show Gist options
  • Save elquimista/df8b245eaf0ae50a0685a0451b1524f5 to your computer and use it in GitHub Desktop.
Save elquimista/df8b245eaf0ae50a0685a0451b1524f5 to your computer and use it in GitHub Desktop.
Calculate combinations count in Javascript (ES5)
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