Question:

What output will be produced by the code below?

var spaceships = Set<String>()
spaceships.insert("Serenity")
spaceships.insert("Enterprise")
spaceships.insert("TARDIS")
spaceships.insert("Serenity")
print(spaceships.count)

Correct answer: 3.

Explanation: Sets are similar to arrays, although each item can only appear once. If you add an item more than once, it will be silently ignored.

 


Keywords:

© 2017 QuizBucket.org