Menu

Ruby Method 1 Rollcalldwarves Method Accept Array Dwarf Names Instance Doc Dopey Bashful G Q43892366

RUBY!

Method 1 — roll_call_dwarves

This method should accept an array of dwarf names, forinstance:

  1. [“Doc”, “Dopey”, “Bashful”, “Grumpy”]

It should then print out each name, in number order, using puts.The print-out should look like this:

  1. Doc
  2. Dopey
  3. Bashful
  4. Grumpy

Look into the each_with_index method.

Once the test for this method is passing, move on to the nextmethod.

Method 2 — summon_captain_planet

This method should accept an array argument of planeteer callsthat will look like this:

  1. planeteer_calls = [“earth”, “wind”, “fire”, “water”,”heart”]

It should then capitalize each element and add an exclamationpoint at the end. The return value of this method should be anarray, in this example:

  1. summon_captain_planet(planeteer_calls)
  2. #=> [“Earth!”, “Wind!”, “Fire!”, “Water!”, “Heart!”]

The .map or .collect method might be appropriate for this task,take a look at it here and here.

Once the test for this method is passing, move on to the nextmethod, long planeteer calls.

Method 3 — long_planeteer_calls

The long_planeteer_calls method should accept an array of calls.The method should tell us if any of the calls are longer than fourcharacters. For example:

  1. short_words = [“puff”, “go”, “two”]
  2. long_planeteer_calls(short_words)
  3. #=> false
  4. assorted_words = [“two”, “go”, “industrious”, “bop”]
  5. long_planeteer_calls(assorted_words)
  6. #=> true

Notice the return value of this method is either true or false,depending on the array it was given as an argument.

Checkout the Ruby docs on arrays for a hint.

Once the test for this method is passing, move on to the lastmethod.

Method 4 — find_the_cheese

The find_the_cheese method should accept an array of strings. Itshould then look through these strings to find and return the firststring that is a type of cheese. The types of cheese that appearare “cheddar”, “gouda”, and “camembert”.

For example:

  1. snacks = [“crackers”, “gouda”, “thyme”]
  2. find_the_cheese(snacks)
  3. #=> “gouda”
  4. soup = [“tomato soup”, “cheddar”, “oyster crackers”,”gouda”]
  5. find_the_cheese(soup)
  6. #=> “cheddar”

If, sadly, a list of ingredients does not include cheese, returnnil:

  1. ingredients = [“garlic”, “rosemary”, “bread”]
  2. find_the_cheese(ingredients)
  3. #=> nil

Expert Answer


Answer to RUBY! Method 1 — roll_call_dwarves This method should accept an array of dwarf names, for instance: [“Doc”, “Dopey”, …

OR