Complete the code to filter numbers greater than 10 using a where clause.
let numbers = [5, 12, 7, 20, 3] let filtered = numbers.filter { number in number [1] 10 }
The where clause filters numbers greater than 10, so the operator should be >.
Complete the code to filter strings with length less than 5 using a where clause.
let words = ["apple", "cat", "banana", "dog"] let shortWords = words.filter { word in word.count [1] 5 }
The where clause filters words with length less than 5, so the operator should be <.
Fix the error in the where clause to filter even numbers.
let nums = [1, 2, 3, 4, 5, 6] let evens = nums.filter { num in num [1] 2 == 0 }
The modulo operator % checks if the remainder is zero, which means the number is even.
Fill both blanks to filter words starting with 'a' and having length greater than 3.
let words = ["apple", "ant", "bat", "arc", "axe"] let filtered = words.filter { word in word.hasPrefix([1]) && word.count [2] 3 }
The prefix should be "a" and length should be greater than 3, so > is correct.
Fill all three blanks to create a dictionary of words with their lengths, filtering words longer than 4 characters.
let words = ["swift", "code", "play", "learn"] let wordLengths = [[1]: [2] for word in words where word.count [3] 4]
The dictionary keys are words, values are their counts, and filter uses > 4 for length.