Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* • If the five cards are equal, the program outputs “Impossible”, otherwise:
- • if four of them are equal, the program outputs “Four of a Kind”, otherwise:
- • if there are three equal and the another two are also equal (example: ‘2’, ‘2’, ‘10’, ‘10’, ‘2’), the program outputs “Full House”, otherwise:
- • if the five are consecutive (example: ‘2’, ‘3’, ‘4’, ‘5’, ‘6’), the program outputs “Straight”, otherwise:
- • if three of them are equal, the program outputs “Three of a Kind”, otherwise:
- • if two pairs contain respectively equal numbers (example ‘A’, ‘K’, ‘A’, ‘K’, ‘J’), the program outputs “Two Pairs”, otherwise:
- • if only two cards are equal, the program outputs “One Pair”, otherwise;
- • the program outputs “Nothing”. */
- function Solve(args) {
- var cards = [];
- for (var i = 0; i < args.length; i++) {
- if (isNaN(args[i])) {
- switch (args[i]) {
- case "A": { cards[i] = 1; break; }
- case "K": { cards[i] = 13; break; }
- case "Q": { cards[i] = 12; break; }
- case "J": { cards[i] = 11; break; }
- }
- } else {
- cards[i] = parseInt(args[i]);
- }
- }
- card = cards.sort(function (a, b) { return a - b; });
- if (cards[0] == cards[1] && cards[0] == cards[2] && cards[0] == cards[3] && cards[0] == cards[4]) {
- return "Impossible";
- }
- if (cards[0] == cards[1] && cards[0] == cards[2] && cards[0] == cards[3] || cards[4] == cards[1] && cards[4] == cards[2] && cards[4] == cards[3]) {
- return "Four of a Kind";
- }
- if ((cards[0] == cards[1] && cards[0] == cards[2] && cards[4] == cards[3]) || (cards[4] == cards[3] && cards[4] == cards[2] && cards[0] == cards[1])) {
- return "Full House";
- }
- if (cards.indexOf(1) == 0) {
- if (cards[4] == 13 && cards[3] == 12 && cards[2] == 11 && cards[1] == 10)
- {
- return "Straight";
- }
- }
- if (cards[4] - cards[3] == 1 && cards[3] - cards[2] == 1 && cards[2] - cards[1] == 1 && cards[1] - cards[0] == 1) {
- return "Straight";
- }
- if ((cards[0] == cards[1] && cards[0] == cards[2]) || (cards[4] == cards[3] && cards[4] == cards[2])) {
- return "Three of a Kind";
- }
- if ((cards[1] == cards[0] || cards[1] == cards[2]) && (cards[3] == cards[2] || cards[3] == cards[4])) {
- return "Two Pairs";
- }
- if (cards[0] == cards[1] || cards[1] == cards[2] || cards[2] == cards[3] || cards[3] == cards[4]) {
- return "One Pair";
- }
- return "Nothing";
- console.log(cards);
- }
Advertisement
Add Comment
Please, Sign In to add comment