Skip to content

Instantly share code, notes, and snippets.

@elquimista
Created November 23, 2016 03:00
Show Gist options
  • Select an option

  • Save elquimista/df8b245eaf0ae50a0685a0451b1524f5 to your computer and use it in GitHub Desktop.

Select an option

Save elquimista/df8b245eaf0ae50a0685a0451b1524f5 to your computer and use it in GitHub Desktop.

Revisions

  1. darkturtle created this gist Nov 23, 2016.
    16 changes: 16 additions & 0 deletions combinations.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    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;
    }
    }