flatMap do when used on nested collections in Swift?flatMap takes a collection of collections and combines them into a single, flat collection by removing one level of nesting.
Given <code>let numbers = [[1, 2], [3, 4], [5]]</code>, what is the result of <code>numbers.flatMap { $0 }</code>?The result is [1, 2, 3, 4, 5]. It merges all inner arrays into one single array.
flatMap different from map when working with nested arrays?map transforms each element but keeps the nested structure, while flatMap transforms and then flattens one level of nesting.
flatMap be used to remove nil values from an array of optionals in Swift?Yes. When used on an array of optionals, flatMap unwraps and removes nil values, returning only non-nil elements.
What is the output of this Swift code?<br><pre>let nested = [["a", "b"], ["c"]]
let result = nested.flatMap { $0.map { $0.uppercased() } }</pre>The output is ["A", "B", "C"]. Each string is uppercased, then all arrays are flattened into one.
flatMap do to a nested array in Swift?flatMap merges nested arrays by removing one level of nesting.
map transforms elements but keeps the original nested structure.
flatMap is used on an array of optionals with some nil values?flatMap unwraps optionals and removes nil values.
let arr = [[1, 2], [3]], what is the result of arr.map { $0.count }?map returns the count of each inner array: 2 and 1.
flatMap applies a transform and flattens the result.
flatMap works on nested collections in Swift and give a simple example.map and flatMap when used on nested arrays.