Answer Key

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Heads up... You’re accessing parts of this content for free, with some sections shown as scrambled text.

Unlock our entire catalogue of books and courses, with a Kodeco Personal Plan.

Unlock now

One way to solve the exercise is as follows:

  var zoo = ["🐈","🐕", "🐍", "🐕", "🐈", "🐕", "🐍", "🐕", "🐕", "🐕", "🐈", "🐍", "🐈", "🐍", "🐍", "🐈"]

  var snakes: [String] = []
  var cats: [String] = []
  var dogs: [String] = []

  for animal in zoo {
    if animal == "🐈" {
  	cats.append(animal)
    } else if animal == "🐕" {
  	dogs.append(animal)
    } else {
  	snakes.append(animal)
    }
  }

  print(snakes)
  print(cats)
  print(dogs)

Remember: Your version doesn’t have to be identical!

See forum comments
Download course materials from Github
Previous: Deliverables