I have a big array containing 52 objects, each representing a specific card in a deck of cards.
var deck = [{'suit': 's', 'value' : A}, {'suit': 'h', 'value' : 9}...]
s
representing the spade suit, and A
for the Ace of spades in this case, and so on.
I have managed (thanks to some guidance from friendly souls here on stackoverflow) to randomize this deck, added 13 of these to a player, and got those to show in an <ul>
on my page.
My problem is, that the values form the deck array i add to the player, i am adding as it is, meaning, the output could be:
♠89A, ♥A29J, ♦KTJ37, ♣8
Which is not optimal.
I would like to be able to sort the cards from A to 2, e.g. ♠AJ72, ♥JT92.. and so on.
Since the deck array will take a huge amount of space, i'm deleteing it from the code i show here. But here is the whole code: Liveweave (pretty sweet codeapp i must say)
This is my javascript:
var deal = function () {
//Player hands
var north_hand = [];
var east_hand = [];
var south_hand = [];
var west_hand = [];
//Creating the deck
var deck = [{'suit': 's', 'value': 'A'}, ... //+51 more cards];
//Call the shuffleDeck function
shuffleDeck(deck);
north_hand = deck.slice(0, 13);
east_hand = deck.slice(13, 26);
south_hand = deck.slice(26, 39);
west_hand = deck.slice(39, 52);
var north_spades = document.getElementById('p1_spades');
var north_hearts = document.getElementById('p1_hearts');
var north_diamonds = document.getElementById('p1_diamonds');
var north_clubs = document.getElementById('p1_clubs');
for (var i = 0; i < north_hand.length; i++) {
if (north_hand[i].suit == "s") {
north_spades.innerHTML += north_hand[i].value;
} else if (north_hand[i].suit == "h") {
north_hearts.innerHTML += north_hand[i].value;
} else if (north_hand[i].suit == "d") {
north_diamonds.innerHTML += north_hand[i].value;
} else {
north_clubs.innerHTML += north_hand[i].value;
}
}
}