Skip to content

Instantly share code, notes, and snippets.

@jrunning
Created July 30, 2014 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrunning/b38befe4c34e9ad1c861 to your computer and use it in GitHub Desktop.
Save jrunning/b38befe4c34e9ad1c861 to your computer and use it in GitHub Desktop.
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