Skip to content

Instantly share code, notes, and snippets.

@rmw
Last active August 29, 2015 14:27
Show Gist options
  • Save rmw/547bcc5d64a1cccc9028 to your computer and use it in GitHub Desktop.
Save rmw/547bcc5d64a1cccc9028 to your computer and use it in GitHub Desktop.
Get all combos of strings in 2 arrays
first_names = %w(rebecca jessica mabel)
middle_names = %w(jean lynn orla amelia)
[].tap do |names|
first_names.each do |first_name|
middle_names.each do |middle_name|
names << "#{first_name} #{middle_name}"
end
end
end
first_names = %w(rebecca jessica mabel)
middle_names = %w(jean lynn orla amelia)
first_names.product(middle_names).map do |name_product|
name_product.join(" ")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment