Question:

What output will be produced by the code below?

var first = [1, 2, 3]
var second = ["one", "two", "three"]
var third = Array(zip(first, second))
print(third)

Correct answer: [(1, "one"), (2, "two"), (3, "three")].

Explanation: This code creates a Zip2Sequence struct out of two arrays: one containing 1, 2, 3, and another containing "one", "two", "three". The Zip2Sequence will match each item in the first array with the item at the same index in the second array, giving (1, "one") and so on. This is then converted to an array for easier access.

 


Keywords:

© 2017 QuizBucket.org