JSFiddle - React, Tailwind, and code Playground

by XGundam05

CoffeeScript

class Card
    constructor: (suit, value) ->
        @Suit = suit
        @Value = value

class Deck
    constructor: ->
        @cards = []
        @currentIndex = 0
        for i in [0..3] by 1
            for j in [1..13] by 1
                switch i
                    when 3 then @cards.push(new Card('Clubs', j))
                    when 2 then @cards.push(new Card('Spades', j))
                    when 1 then @cards.push(new Card('Hearts', j))
                    when 0 then @cards.push(new Card('Diamonds', j))
    
    Shuffle: ->
        for i in [51..0] by -1
            k = Math.floor(Math.random() * i)
            _tmp = @cards[i]
            @cards[i] = @cards[k]
            @cards[k] = _tmp
        @currentIndex = 0
    
    List: ->
        for i in [0..51] by 1
            console.log(@cards[i])
    
    Draw: (n) ->
        hand = []
        _curIndex = @currentIndex
        if(@currentIndex < 52)
            if(n > 52 - @currentIndex)
                n = 52 - @currentIndex
            n = n - 1
            for i in [0..n] by 1
                hand.push(@cards[i + _curIndex])
                @currentIndex++
        return hand

deck = new Deck()
_hand = deck.Draw(5)
while _hand.length > 0
    console.log('hand')
    for i in [0.._hand.length - 1] by 1
        console.log(_hand[i])
    _hand = deck.Draw(5)
console.log(deck)