     # Straight Flush
     if (same_suit)
         # check if all cards have consecutive values
-        if (!![1..4].reduce (b, i) -> b & (hand[i-1].value + 1 == hand[i].value))
+        if (!![1..4].reduce (b, i) -> b && (hand[i-1].value + 1 == hand[i].value))
             return [7].concat(values)
+
+        # Flush
+        return [5].concat(values)
+    else
+        # Four of a kind
+        # card are ordered, so we check
+        #    if values[1] == values[2] == values[3] == values[0]
+        # or if values[1] == values[2] == values[3] == values[4]
+        for i in [0, 4]
+            if (!!values[1..3].reduce (b, c) -> b && (c == values[i]))
+                return [6].concat(values)
 
     # TODO
 



    #renamining hand_types : [ 'High Card', 'Pair', 'Two Pairs', 'Three of a Kind', 'Straight',
    #'Flush', 'Full House', 'Four of a kind' ]

exports.compare_hands = compare_hands


            return 'Tie.' if (i == 5)

    else if (p[1].type[0] > p[2].type[0])
        return result.replace('%1', p[1].name)
                     .replace('%2', type_to_s(p[1].type[0]))

    else
        return result.replace('%1', p[2].name)
                     .replace('%2', type_to_s(p[2].type[0]))



