
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Determine Full House in Poker using JavaScript
The “full house in poker” is a situation when a player, out of their five cards, has at least three cards identical. We are required to write a JavaScript function that takes in an array of five elements representing a card each and returns true if there's a full house situation, false otherwise.
Example
Following is the code −
const arr2 = ['K', '2', 'K', 'A', 'J']; const isFullHouse = arr => { const copy = arr.slice(); for(let i = 0; i < arr.length; ){ const el = copy.splice(i, 1)[0]; if(copy.includes(el)){ copy.splice(copy.indexOf(el), 1); if(copy.includes(el)){ return true; } }else{ i++; } }; return false; }; console.log(isFullHouse(arr1)); console.log(isFullHouse(arr2));
Output
Following is the output in the console −
true false
Advertisements