Last active
September 14, 2021 17:51
-
-
Save JRiggles/4814961a48f70613a6205c9c45ea42a1 to your computer and use it in GitHub Desktop.
Takes an input array and pairs each element with another from the array. Elements cannot be paired with themselves.
This file contains hidden or 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
a = %w[A B C D E F G H] | |
a.shuffle!.zip(a.rotate).sort.each { |k,v| puts "#{k}=>#{v}" } | |
# example return value: | |
# A=>E | |
# B=>D | |
# C=>A | |
# D=>H | |
# E=>B | |
# F=>C | |
# G=>F | |
# H=>G |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment