Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Solve(args) {
- var dealtCards = args.split(", ");
- var ranks = ['2', '3', '4', '5', '6', '7', '8', '9', "10", 'J', 'Q', 'K', 'A'];
- var suites = ['S', 'H', 'D', 'C'];
- var allCards = [];
- for(var i = 0; i < suites.length; i++) {
- for(var j = 0; j < ranks.length; j++) {
- allCards.push(ranks[j] + suites[i]);
- }
- }
- var isPrinted = false;
- for (var i = 0; i < allCards.length-4; i++) {
- if((dealtCards.indexOf(allCards[i]) != -1) &&
- (dealtCards.indexOf(allCards[i+1]) != -1) &&
- (dealtCards.indexOf(allCards[i+2]) != -1) &&
- (dealtCards.indexOf(allCards[i+3]) != -1) &&
- (dealtCards.indexOf(allCards[i+4]) != -1) &&
- (allCards[i].charAt(allCards[i].length-1) ==
- (allCards[i+1].charAt(allCards[i+1].length-1)) &&
- (allCards[i+1].charAt(allCards[i+1].length-1) ==
- allCards[i+2].charAt(allCards[i+2].length-1)) &&
- (allCards[i+2].charAt(allCards[i+2].length-1) ==
- allCards[i+3].charAt(allCards[i+3].length-1)) &&
- (allCards[i+3].charAt(allCards[i+3].length-1) ==
- allCards[i+4].charAt(allCards[i+4].length-1)))) {
- console.log("[" + allCards[i] + ", " +
- allCards[i+1] + ", " +
- allCards[i+2] + ", " +
- allCards[i+3] + ", " +
- allCards[i+4] + "]");
- isPrinted = true;
- }
- }
- if(!isPrinted) {
- console.log("No Straight Flushes");
- }
- }
- Solve("9D, 2S, 10D, AD, 10H, JD, QD, KD");
- Solve("AS, KH, 10C");
- Solve("2S, 2C, 2D, 2H, AS, KH, 10C");
- Solve("5H, AS, 10C, 8H, KS, KH, KD, 9H, JH, QS, 3H, QD, 4H, QH, 8S, 10D, 6H, 10S, 10H, 7C, JD, JS, 2H, 7S, 7D");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement