Skip to content

Instantly share code, notes, and snippets.

@epoch
Last active December 7, 2021 03:28
Show Gist options
  • Save epoch/8292180 to your computer and use it in GitHub Desktop.
Save epoch/8292180 to your computer and use it in GitHub Desktop.
arrays

1. Create an array of the days of the week

  • Create a variable named days_of_the_week as an array of the following:
    • Sunday
    • Monday
    • Tuesday
    • Wednesday
    • Thursday
    • Friday
    • Saturday

2. My calendar says the first day is Monday...

  • Remove Sunday from the first postion and move it to the last position. Use array methods.

3. Create a new array of the days of the week:

you can do this programmatically or just type in manually

  • The first inner array should be the weekdays
  • The second inner array should be the weekend days

4. Remove either the weekdays or the weekends

Your choice...

5. Sort the remaining days alphabetically

more arrays

Starting with the following array...

remember to test your code and use (irb/pry/p)!

planeteers = ["Earth", "Wind", "Captain Planet", "Fire", "Water"]

Access the second value in planeteers.

# Your answer here

Add "Heart" to the end of planeteers.

# Your answer here

Combine planeteers with rangers = ["Red", "Blue", "Pink", "Yellow", "Black"] and save the result in a variable called heroes.

# Your answer here

Alphabetize the contents of heroes using a method. The Ruby documentation might help.

# Your answer here

Randomize the contents of heroes using a method. The Ruby documentation might help.

# Your answer here

Select a random element from heroes using a method. The Ruby documentation might help.

# Your answer here

display each hero in a new line on the terminal using the .each method

# Your answer here

display each hero in a new line on the terminal using the .each method only if the hero starts with the letter 'W'

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