Skip to content

Instantly share code, notes, and snippets.

@sgrshah
Created June 10, 2013 20:02
Show Gist options
  • Save sgrshah/5751773 to your computer and use it in GitHub Desktop.
Save sgrshah/5751773 to your computer and use it in GitHub Desktop.
simple arrays, sagar
# 1. Construct an array with your favorite foods. It should have at least 5 elements
favorite_foods = ["pav bhaji", "pizza", "falafel", "burrito", "egg & cheese"]
# Write a puts which returns your most favorite food out of the array.
puts favorite_foods[0]
# Construct an array with the colors of the rainbow (ROYGBIV)
rainbow_array = ["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
# Slice the colors Red, Orange, and Yellow out of the array.
puts rainbow_array.slice(0,3)
# Create an empty array.
empty_array =[]
# Assign values to the the second and 6th position.
empty_array[1] = "value 2"
empty_array[5] = "value 6"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment