Objectives
You're going to get familiar with iterating through arrays in a more swifty way.
Instructions
Nothing to clone here! Just use the instructions and build your own file from scratch. No tests on this one.
There are four methods to complete in this lab:
- Dwarf Roll Call
- Summon Captain Planet
- Long Planteer Calls
- Find the Cheese
Method 1 - Dwarf Roll Call
This method should accept an array of dwarf names, for instance:
["Doc", "Dopey", "Bashful", "Grumpy"]
It should then print out each name using print()
. The print-out should look like this:
- Doc
- Dopey
- Bashful
- Grumpy
Look up the enumerate
method, it might help you out here.
Method 2 - Summon Captain Planet
This method should accept an array of planeteer calls, like this:
planeteerCalls = ["earth", "wind", "fire", "water", "heart"]
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:
["Earth!", "Wind!", "Fire!", "Water!", "Heart!"]
You have a few options to make this work, try the map
method.
Method 3 - Long Planeteer Calls
The longPlaneteerCalls
method should accept an array of calls. The method should tell us if any of the calls are longer than four characters by returning a BOOL
.
You have a couple of options here to make this work. Try the filter
method.
Method 4 - Find the Cheese
The findTheCheese
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:
snacks = ["crackers", "gouda", "thyme"]
findTheCheese(snacks)
// returns back "gouda"
soup = ["tomato soup", "cheddar", "oyster crackers", "gouda"]
findTheCheese(soup)
// returns back "cheddar"
If, sadly, a list of ingredients does not include cheese, return "not found":
ingredients = ["garlic", "rosemary", "bread"]
findTheCheese(ingredients)
// returns back "not found"
You can assume that all strings will be lowercase.