Last active
April 22, 2020 07:39
-
-
Save ellcs/8004712382c45378a0f731e9e830312b to your computer and use it in GitHub Desktop.
Helpful ruby oneliners
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
# create random groups of people | |
%w(james bob alice eve tux).shuffle.each_slice(2).to_a | |
# => [["bob", "eve"], ["alice", "tux"], ["james"]] | |
# assign random tools to people (tools can be empty) | |
people = %w(james bob alice eve tux) | |
tools = %w(hammer chainsaw screwdriver) | |
people.shuffle.zip(tools) | |
# => [["alice", "hammer"], ["james", "screwdriver"], ["tux", "chainsaw"], ["bob", nil], ["eve", nil]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment