If I have a sorted array, how do I find the sequential numbers? Btw, this is for determining if a poker hand is a straight or not. Duplicates in the array have been removed. I can do this, but it would be a multi-line method and I thought there might be a quick one liner using an Enumerable method.
For example:
FindSequence([9,8,7,5,4]) = [9,8,7]
FindSequence([4,2,0]) = nil
Assuming it is presorted, you can easily test for a straight like so:
To be safe you may want to add the sort:
But if you really need to extract the largest sequence, it will take another solution.