Best Poker Hand Lab

16.1% Acceptance

In this lab, you will work on a problem related to the popular card game of poker. You are given an integer array ranks and a character array suits, representing the ranks and suits of 5 cards. Your task is to create a function bestHand(ranks, suits) that returns a string representing the best type of poker hand you can make with the given cards. Remember that the return values are case-sensitive.

The following are the types of poker hands you can make from best to worst:

  1. "Flush": Five cards of the same suit.
  2. "Three of a Kind": Three cards of the same rank.
  3. "Pair": Two cards of the same rank.
  4. "High Card": Any single card.


1bestHand([13,2,3,1,9], ["a","a","a","a","a"]) 2// Output: "Flush" 3// Explanation: The hand consists of 5 cards with the same suit, so we have a "Flush". 4 5bestHand([4,4,2,4,4], ["d","a","a","b","c"]) 6// Output: "Three of a Kind" 7// Explanation: The hand consists of 3 cards with the same rank, so we have a "Three of a Kind". 8 9bestHand([10,10,2,12,9], ["a","b","c","a","d"]) 10// Output: "Pair" 11// Explanation: The hand consists of 2 cards with the same rank, so we have a "Pair".


  • ranks.length == suits.length == 5
  • 1 <= ranks[i] <= 13
  • 'a' <= suits[i] <= 'd'
  • No two cards have the same rank and suit.

Note: You will need to export the bestHand function in order to run the evaluation script. You can do this by adding the following line at the end of your code:

export default bestHand;

Once you have completed the implementation of the bestHand function, the evaluation script will automatically test your solution against several test cases to ensure it is correct. Good luck!