@leofavre/memory-game-component
Version:
A memory game web component.
54 lines (37 loc) • 1.41 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isGameOver = exports.isVisiblePairOfCardsAMatch = exports.isPairOfCardsVisible = exports.isCardInTheGame = exports.isCardMatched = exports.isCardRevealed = exports.getCardAtPosition = exports.getNumberOfCards = void 0;
const getNumberOfCards = ({
cards
}) => cards.length * 2;
exports.getNumberOfCards = getNumberOfCards;
const getCardAtPosition = (position, {
cards
}) => cards.find(card => card.positions.includes(position));
exports.getCardAtPosition = getCardAtPosition;
const isCardRevealed = (position, {
revealed
}) => revealed.includes(position);
exports.isCardRevealed = isCardRevealed;
const isCardMatched = (position, {
matched
}) => matched.includes(position);
exports.isCardMatched = isCardMatched;
const isCardInTheGame = (position, {
revealed,
matched
}) => revealed.includes(position) || matched.includes(position);
exports.isCardInTheGame = isCardInTheGame;
const isPairOfCardsVisible = ({
revealed
}) => revealed.length === 2;
exports.isPairOfCardsVisible = isPairOfCardsVisible;
const isVisiblePairOfCardsAMatch = ({
revealed,
matched
}) => revealed.every(position => matched.includes(position));
exports.isVisiblePairOfCardsAMatch = isVisiblePairOfCardsAMatch;
const isGameOver = state => getNumberOfCards(state) === state.matched.length;
exports.isGameOver = isGameOver;