Skip to content

Instantly share code, notes, and snippets.

@DawnPaladin
Created January 8, 2017 03:14
Show Gist options
  • Save DawnPaladin/95c31a9b7ed9edc56f63d14035d21045 to your computer and use it in GitHub Desktop.
Save DawnPaladin/95c31a9b7ed9edc56f63d14035d21045 to your computer and use it in GitHub Desktop.
def advanced(sock_pile)
sock_book = Hash.new(Array.new)
pairs = []
sock_pile.each do |sock|
if sock_book[sock].length > 0
pairs.push([sock, sock_book[sock].pop])
else
sock_book[sock].push(sock)
end
end
pairs
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment