Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8222015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:07:53+00:00 2026-06-07T14:07:53+00:00

I have following C# code and is it possible to do an easy convert

  • 0

I have following C# code and is it possible to do an easy convert in to JavaScript? I need this to run 100% in the browser.

As I do understand enum does not exist and can be replaced with a strings instead.

In short I have a class Deck witch holds an array of Card, the class Card does have a few properties including rank, symbol etc. and also a shuffle function.

I don’t expect anyone to convert all my code here but give me pointer how something similar can be done.

public enum Suit
{
    Club,
    Diamond,
    Heart,
    Spade
};

public class Card
    {
    public Suit suit;
    public int value;
    public string text;
    public int HCP;

    public Card()
    {
    }

    public Card(Suit _suit, int _value, int _HCP, string _text)
    {
        suit = _suit;
        value = _value;
        HCP = _HCP;
        text = _text;
    }
};

public class Deck
{
    public Card[] Cards = new Card[52];
    public Deck()
    {
        Cards[0] = new Card(Suit.Spade, 14, 4, "A");
        Cards[1] = new Card(Suit.Spade, 13, 3, "K");
        Cards[2] = new Card(Suit.Spade, 12, 2, "Q");
        Cards[3] = new Card(Suit.Spade, 11, 1, "J");
        Cards[4] = new Card(Suit.Spade, 10, 0, "T");
        Cards[5] = new Card(Suit.Spade, 9, 0, "9");
        Cards[6] = new Card(Suit.Spade, 8, 0, "8");
        Cards[7] = new Card(Suit.Spade, 7, 0, "7");
        Cards[8] = new Card(Suit.Spade, 6, 0, "6");
        Cards[9] = new Card(Suit.Spade, 5, 0, "5");
        Cards[10] = new Card(Suit.Spade, 4, 0, "4");
        Cards[11] = new Card(Suit.Spade, 3, 0, "3");
        Cards[12] = new Card(Suit.Spade, 2, 0, "2");

        Cards[13] = new Card(Suit.Heart, 14, 4, "A");
        Cards[14] = new Card(Suit.Heart, 13, 3, "K");
        Cards[15] = new Card(Suit.Heart, 12, 2, "Q");
        Cards[16] = new Card(Suit.Heart, 11, 1, "J");
        Cards[17] = new Card(Suit.Heart, 10, 0, "T");
        Cards[18] = new Card(Suit.Heart, 9, 0, "9");
        Cards[19] = new Card(Suit.Heart, 8, 0, "8");
        Cards[20] = new Card(Suit.Heart, 7, 0, "7");
        Cards[21] = new Card(Suit.Heart, 6, 0, "6");
        Cards[22] = new Card(Suit.Heart, 5, 0, "5");
        Cards[23] = new Card(Suit.Heart, 4, 0, "4");
        Cards[24] = new Card(Suit.Heart, 3, 0, "3");
        Cards[25] = new Card(Suit.Heart, 2, 0, "2");

        Cards[26] = new Card(Suit.Diamond, 14, 4, "A");
        Cards[27] = new Card(Suit.Diamond, 13, 3, "K");
        Cards[28] = new Card(Suit.Diamond, 12, 2, "Q");
        Cards[29] = new Card(Suit.Diamond, 11, 1, "J");
        Cards[30] = new Card(Suit.Diamond, 10, 0, "T");
        Cards[31] = new Card(Suit.Diamond, 9, 0, "9");
        Cards[32] = new Card(Suit.Diamond, 8, 0, "8");
        Cards[33] = new Card(Suit.Diamond, 7, 0, "7");
        Cards[34] = new Card(Suit.Diamond, 6, 0, "6");
        Cards[35] = new Card(Suit.Diamond, 5, 0, "5");
        Cards[36] = new Card(Suit.Diamond, 4, 0, "4");
        Cards[37] = new Card(Suit.Diamond, 3, 0, "3");
        Cards[38] = new Card(Suit.Diamond, 2, 0, "2");

        Cards[39] = new Card(Suit.Club, 14, 4, "A");
        Cards[40] = new Card(Suit.Club, 13, 3, "K");
        Cards[41] = new Card(Suit.Club, 12, 2, "Q");
        Cards[42] = new Card(Suit.Club, 11, 1, "J");
        Cards[43] = new Card(Suit.Club, 10, 0, "T");
        Cards[44] = new Card(Suit.Club, 9, 0, "9");
        Cards[45] = new Card(Suit.Club, 8, 0, "8");
        Cards[46] = new Card(Suit.Club, 7, 0, "7");
        Cards[47] = new Card(Suit.Club, 6, 0, "6");
        Cards[48] = new Card(Suit.Club, 5, 0, "5");
        Cards[49] = new Card(Suit.Club, 4, 0, "4");
        Cards[50] = new Card(Suit.Club, 3, 0, "3");
        Cards[51] = new Card(Suit.Club, 2, 0, "2");
    }
    public void Shuffle(Random r)
    {
        for (int n = Cards.Length - 1; n > 0; --n)
        {
            int k = r.Next(n + 1);
            Card temp = Cards[n];
            Cards[n] = Cards[k];
            Cards[k] = temp;
        }
    }
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:07:56+00:00Added an answer on June 7, 2026 at 2:07 pm

    Enums can be converted to hashes:

    var Suit = {
      Club: 0,
      Diamond: 1,
      Heart: 2,
      Spade: 4
    };
    

    The Card class is dead simple:

    function Card(suit, value, hcp, text) {
      this.suit = suit;
      this.value = value;
      this.hcp = hcp;
      this.text = text;
    }
    

    And Deck too:

    function Deck() {
      this.cards = [
        new Card(Suit.Heart, 14, 4 "A"),
        new Card(Suit.Heart, 13, 3 "K"),
        // ...
      ];
    }
    

    Then add shuffle to Deck:

    Deck.prototype.shuffle = function() {
      this.cards.sort(function() { return 0.5 - Math.random() });
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Are file descriptors shared when fork()ing? Suppose I have following code in
Suppose I have the following code to collect all the possible combinations. abArray =
I have the following code which I use to match fancybox possible elements: $('a.grouped_elements').each(function(){
I have the following PHP code which works out the possible combinations from a
I have following code. ASPX Page <a href=AnyASPXPageOfWebsite.aspx onclick=javascript:CallJQuery(); > Set Price </a> JS
Is the following easy to code? I have a tableview and when the user
I have following code in initialization im = imread('Image02.tif'); figure(); imagesc(im); colormap(gray); [hImage hfig
I have following code <div id=main> <div id=one> </div> <div id=two> </div> <div id=three>
I have following code for updating user's column public void UpdateLastModifiedDate(string username) { using
I have following code for loading image from url in xml parsing endElement method

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.