Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.6 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
68ee9e3066cfd4eb2328e8a8 Challenge 89: Counting Cards 28 challenge-89

--description--

A standard deck of playing cards has 13 unique cards in each suit. Given an integer representing the number of cards to pick from the deck, return the number of unique combinations of cards you can pick.

  • Order does not matter. Picking card A then card B is the same as picking card B then card A.

For example, given 52, return 1. There's only one combination of 52 cards to pick from a 52 card deck. And given 2, return 1326, There's 1326 card combinations you can end up with when picking 2 cards from the deck.

--hints--

combinations(52) should return 1.

assert.equal(combinations(52), 1);

combinations(1) should return 52.

assert.equal(combinations(1), 52);

combinations(2) should return 1326.

assert.equal(combinations(2), 1326);

combinations(5) should return 2598960.

assert.equal(combinations(5), 2598960);

combinations(10) should return 15820024220.

assert.equal(combinations(10), 15820024220);

combinations(50) should return 1326.

assert.equal(combinations(50), 1326);

--seed--

--seed-contents--

function combinations(cards) {

  return cards;
}

--solutions--

function combinations(cards) {
  const n = 52;

  function factorial(x) {
    let result = 1;
    for (let i = 2; i <= x; i++) {
      result *= i;
    }
    return result;
  }

  return factorial(n) / (factorial(cards) * factorial(n - cards));
}