Giter VIP home page Giter VIP logo

apples-and-holidays-online-web-prework's Introduction

Iterating Over Hashes

Objectives

  1. Iterate over nested, or multidimensional, hashes.

The Holiday Suppliers

Instructions

You have a bunch of decorations for various holidays organized by season.

holiday_supplies = {
  :winter => {
    :christmas => ["Lights", "Wreath"],
    :new_years => ["Party Hats"]
  },
  :summer => {
    :fourth_of_july => ["Fireworks", "BBQ"]
  },
  :fall => {
    :thanksgiving => ["Turkey"]
  },
  :spring => {
    :memorial_day => ["BBQ"]
  }
}

Write your methods in lib/holiday.rb; use the comments in each method as guides.

  • Write a method that returns the second supply for the Fourth of July. For eg:
def second_supply_for_fourth_of_july(holiday_supplies)
  holiday_supplies[:summer][:fourth_of_july][1]
end
  • Write a method that adds a supply to both Winter holidays.

  • Write a method that adds a supply to Memorial Day.

  • Write a method that adds a new holiday and its associated supplies to any season.

  • Write a method to collect all Winter supplies from all the winter holidays. For eg:

winter_supplies(holiday_supplies) #=> ["Lights", "Wreath", etc]
  • Write a method that uses a loop to list out all the supplies you have for each holiday and the season. Use string manipulation to get your output to match what the test is expecting.

  • Here are a few helpful tips:

    • Our hash keys are symbols. We need to convert them into strings. Use the .to_s method on a symbol to convert it into a string.
    • Look closely at the output string that the test is expecting. You'll notice that it expects holiday names, like "New Years", to have both words capitalized. Ruby has a .capitalize method that you can call on a string. But, note:
      • .capitalize returns the capitalized string but doesn't change the original string. So, when you call on that same string in the future, it isn't capitalized! You can capitalize a string for now and evermore by using the bang operator (!).
      • You'll need to capitalize both words in a given holiday's name. If you call "new years".capitalize!, it will return "New years". In order to capitalize both words, you'll need to .split the string into an array and iterate over that array to .capitalize! each word in it. Then, you'll need to .join the array back into a string.
      • If you're unfamiliar with the methods mentioned above, look them up in the Ruby documentation.

Example of expected output:

Winter:
  Christmas: Lights, Wreath
  New Years: Party Hats
  • Write a method to collect all holidays with "BBQ" in the supply array. The method should behave as seen below:
holidays_with_bbqs(holiday_supplies)
#=> [:fourth_of_july, :memorial_day]

Reminder: This is a challenging lab, so remember to use Pry, Google, and the Learn community to help you get the tests passing.

Resources

View Iterating Over Hashes on Learn.co and start learning to code for free.

apples-and-holidays-online-web-prework's People

Contributors

ahimmelstoss avatar annjohn avatar arelenglish avatar aviflombaum avatar benjagross avatar bhollan avatar deniznida avatar fislabstest avatar fs-lms-test-bot avatar ga-be avatar gilmoursa avatar irmiller22 avatar jmburges avatar jrodden1 avatar kthffmn avatar loganhasson avatar matthewkrey avatar msuzoagu avatar ngevan avatar pletcher avatar roseweixel avatar sammarcus avatar sarogers avatar sophiedebenedetto avatar tsiege avatar victhevenot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.