Skip to content

Instantly share code, notes, and snippets.

@sjgjohnston
Forked from featherart/gist:6745715
Last active December 24, 2015 04:49
Show Gist options
  • Save sjgjohnston/6746611 to your computer and use it in GitHub Desktop.
Save sjgjohnston/6746611 to your computer and use it in GitHub Desktop.
# create an Array of 4 shoes
puts "01 ------" # to make the output easier to see...
shoes = ["loafers", "heels", "doc martins", "winklepickers"]
p shoes
# iterate through your Array using each and {}'s
# and show a list of your shoes
puts "02 ------" # to make the output easier to see...
shoes.each { |shoe| puts shoe}
# create an Array of 4 outfits using Array.new
puts "03 ------" # to make the output easier to see...
outfits = Array.new(["motorcycle", "scuba", "tuxedo", "sweats"])
p outfits
# iterate through your outfits using a Range and do\end
# and print them out
puts "04 ------" # to make the output easier to see...
outfits[0..3].each do |outfit|
puts outfit
end
# Shuffle each Array
puts "05 ------" # to make the output easier to see...
shoes = shoes.shuffle
outfits = outfits.shuffle
# iterate through your Arrays and puts each outfit with each shoes
# using any form of iteration that floats your boat!
puts "06 ------" # to make the output easier to see...
outfits.each_with_index do |outfit, index|
puts "#{shoes[index]}' + #{outfit}'"
end
# A friend needs some shoes, so give her the last pair
puts "07 ------" # to make the output easier to see...
p shoes.last
# now you need a new pair, so push one in
puts "08 ------" # to make the output easier to see...
p shoes.push("flip-flops")
# each outfit now needs to have "super duper" added to the front
# use a map to do this & make sure it stays that way
puts "09 ------" # to make the output easier to see...
p outfits.map! { |outfit| outfit = "super duper #{outfit}" }
# each pair of shoes now needs a "!" after it
# do this using a map, but don't change the original Array
puts "10 ------" # to make the output easier to see...
p shoes.map { |shoe| shoe += "!" }
# Shuffle each Array again then print out a new
# set of outfits + shoes, mapping a "!!" on the end of each
puts "11 ------" # to make the output easier to see...
shoes = shoes.shuffle
outfits = outfits.shuffle
outfits.each_with_index do |outfit, index|
outfit = outfit += "!!"
shoe = shoes[index] += "!!"
puts "#{outfit} + #{shoe}"
end
# Create a big Array called wardrobe by adding your shoes and outfits
puts "12 ------" # to make the output easier to see...
wardrobe = shoes + outfits
p wardrobe
# iterate through your wardrobe & print the contents using each
puts "13 ------" # to make the output easier to see...
wardrobe.each { |item| puts item}
# Spring cleaning! slice out 3 elements in the middle
# for donation. Verify wardrobe now contains 5 elements & donation 3
puts "14 ------" # to make the output easier to see...
donation = wardrobe.slice!(3..5)
p wardrobe
p donation
# You are fickle! Decide to keep donation items using push
# make sure you still just have a big Array and not an
# Array of Arrays
puts "15 ------" # to make the output easier to see...
donation.each do |item|
wardrobe.push(item)
end
p wardrobe
## Feather - I am not sure why I couldn't get the following to work...
#p wardrobe.push(donation).flatten
# print out each element in your wardrobe with a "OMFG!"
# added to the end of it, do this using each then with map
puts "16 ------" # to make the output easier to see...
wardrobe.each {|item| puts "#{item} OMFG!"}
puts "17 ------" # to make the output easier to see...
wardrobe.map {|item| item += " OMFG!"; puts item}
# You've joined a cult!
# permanently add "purple " to each item of your wardrobe
puts "18 ------" # to make the output easier to see...
wardrobe.map! {|item| item += " purple"}
puts wardrobe
# Now use each to print out your new cultish wardrobe
puts "19 ------" # to make the output easier to see...
wardrobe.each {|item| puts "#{item}"}
# each pair of shoes now needs a "!" after it
# do this using a map, but don't change the original Array
puts "20 ------" # to make the output easier to see...
puts shoes.map { |pair| pair += "!" }
# Shuffle each Array again then print out a new
# set of outfits + shoes, mapping a "!" on the end of each
puts "21 ------" # to make the output easier to see...
shoes = shoes.shuffle
outfits = outfits.shuffle
#wardrobe = wardrobe.shuffle
outfits.each_with_index do |outfit, index|
outfit = outfit += "!"
shoe = shoes[index] += "!"
puts "#{outfit} + #{shoe}"
end
@featherart
Copy link

Nicely done! Not sure what winklepinkers are though :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment