Created
July 6, 2016 21:30
-
-
Save charleshkang/3b50cc0b48c826574bfe6d2b8568eb11 to your computer and use it in GitHub Desktop.
Stupid Cats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Below is a code that creates an array of Cat objects and an array | |
of their meowPatterns. | |
Can you match pattern with the cat, store the pattern variable inside the | |
Cat and modify the “meow” function to print either “MEOW” or “meow”? | |
1. Match the meowPatterns with cats and store its pattern inside the Cat | |
object | |
itt | |
2. Modify the Cat object’s meow function to print the cat’s name and | |
the meowing pattern (see below) | |
3. Call each cat and tell that cat to meow. | |
*/ | |
// meow, MEOW, MEOW should print + cat' name | |
var meowPatterns = [“.-.-“, “-.-.-.”, “—..-..-..”] | |
// iterate over cats, and assign pattern to cat | |
for cat in cats { | |
cat.pattern = | |
} | |
for meow in meowPatterns { | |
} | |
class Cat { | |
var name = “” | |
var pattern = “” | |
init (name: String) { | |
self.name = name | |
} | |
func meow() { | |
} | |
} | |
/* | |
Here, print “MEOW” if you get “-“ and “meow” if you get “.”, | |
along with the cat’s name. | |
Example input: | |
“.-.-“ | |
Example output: | |
“Mittens: meowMEOWmeowMEOW” | |
*/ | |
var cats = [Cat(name: “Whiskers”), Cat(name: “Mittens”), Cat(name: “Smokey”)] | |
// Tell each cat to meow here. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment