Created
July 30, 2014 17:46
-
-
Save jrunning/b38befe4c34e9ad1c861 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr = [89, 52, 52, 36, 18, 18, 18, 7] | |
def rank_em(arr, accum=[], rank=0, run=0, last_head=nil) | |
head, *rest = arr | |
return accum if head.nil? | |
run += 1 | |
unless head == last_head | |
rank += run | |
run = 0 | |
end | |
rank_em(rest, accum.push(rank), rank, run, head) | |
end | |
p rank_em(arr) | |
# => [1, 2, 2, 4, 5, 5, 5, 5, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment