Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Returning poker pair cards - JavaScript
We are required to write a function that takes in an array of exactly five elements representing the five cards of a poker player drawn randomly.
If the five cards contain at least one pair, our function should return the card number of the highest pair (trivial if there only exists a single pair). Else our function should return false.
For example: If the array is −
const arr = ['A', 'Q', '3', 'A', 'Q'];
Then our function should return −
'A' (as 'A' > 'Q' in card games)
Example
Following is the code −
const arr = ['A', 'Q', '3', 'A', 'Q'];
const greatestPair = arr => {
const legend = '23456789JQKA';
const pairs = [];
for(let i = 0; i legend.indexOf(b) - legend.indexOf(a));
return pairs[0];
};
console.log(greatestPair(arr));
Output
Following is the output in the console −
A
Advertisements
