if (hand = hand) then we must have trips of four of a kind, if (hand + 4 = hand) we must have a straight. PPS If we are going for pure speed optimisation there still may be optimisations possible along the lines of some of things suggested by others above (i.e. PS there could by logic errors in here, the concept is sound, but its purely typed in to a browser.
One problem with code like this is its not super easy to tell whats going on at first glance as it relies on implicit properties of the sorted set.