Complete the code to find the first element in the array.
let numbers = [1, 2, 3, 4, 5] let firstNumber = numbers.[1]
The first() method returns the first element of the array.
Complete the code to filter numbers greater than 3.
let numbers = [1, 2, 3, 4, 5] let filtered = numbers.filter { $0 [1] 3 }
The filter method keeps elements where the condition is true. Here, we want numbers greater than 3.
Fix the error in the code to sum all numbers in the array.
let numbers = [1, 2, 3, 4, 5] let total = numbers.reduce(0, [1])
The reduce method combines all elements using the closure. To sum, add the accumulator and current value.
Fill both blanks to create a dictionary of word lengths for words longer than 3 characters.
let words = ["apple", "bat", "car", "door"] let lengths = [String: Int](uniqueKeysWithValues: words.filter { $0.count [1] 3 }.map { ($0, $0.[2]) })
Filter words with count greater than 3, then map each word to a tuple of (word, word.count).
Fill all three blanks to create a dictionary with uppercase keys and values greater than 2.
let data = ["one": 1, "two": 2, "three": 3] let result = data.filter { $0.value [1] 2 }.mapKeys { $0.key.[2]() }.mapValues { $0.[3] }
Filter values greater than 2, convert keys to uppercase, and convert values to strings using description.