Cartoon Collections Lab
Cartoon Collections
Objectives
Get familiar iterating through arrays with enumerator methods like
.collect
or.map
,.find
, and.include?
.Build methods and control their return values.
Practice control flow with
if
andelse
statements.
Instructions
There are four methods to complete in this lab:
roll_call_dwarves
summon_captain_planet
long_planeteer_calls
find_the_cheese
Method 1 — roll_call_dwarves
roll_call_dwarves
This method should accept an array of dwarf names, for instance:
It should then print out each name, in number order, using puts
. The print-out should look like this:
Doc
Dopey
Bashful
Grumpy
Look into the each_with_index
method.
Once the test for this method is passing, move on to the next method.
Method 2 — summon_captain_planet
summon_captain_planet
This method should accept an array argument of planeteer calls that will look like this:
It should then capitalize each element and add an exclamation point at the end. The return value of this method should be an array, in this example:
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 next method, long planeteer calls.
Method 3 — long_planeteer_calls
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 four characters. For example:
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 last method.
Method 4 — find_the_cheese
find_the_cheese
The find_the_cheese
method should accept an array of strings. It should then look through these strings to find and return the first string that is a type of cheese. The types of cheese that appear are "cheddar"
, "gouda"
, and "camembert"
.
For example:
If, sadly, a list of ingredients does not include cheese, return nil
:
You can assume that all strings will be lowercase. Take a look at the .include
method for a hint. This method asks you to return a string value instead of printing it so keep that in mind.
Resources
The
.map
methodThe
.include
method
View Cartoon Collections Lab on Learn.co and start learning to code for free.
Last updated