UNPKG

cardation

Version:

fundation of card games, card model

36 lines (35 loc) 1.07 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const CardError_1 = require("../../error/CardError"); class Pair { /** * Test if the cards form a pair. * @param {Card[]} cards cards to be tested * @returns {boolean} true if the cards form a pair */ static isPair(cards) { if (cards.length !== 2) { return false; } const [firstCard] = cards; if (firstCard.getRank() !== cards[1].getRank()) { return false; } return true; } _cards; constructor(cards) { if (cards.length !== 2) { throw new CardError_1.default('[Pair][constructor]: there must be two cards to form a pair!'); } const [firstCard] = cards; if (!firstCard.equals(cards[1])) { throw new CardError_1.default('[Pair][constructor]: the two cards must be identical to form a pair!'); } this._cards = [...cards]; } getCards() { return [...this._cards]; } } exports.default = Pair;