Swift
Higher-order functions
What does this code print?
let raw = ["1", "x", "3"]
let a = raw.map { Int($0) }
let b = raw.compactMap { Int($0) }
let c = [[1, 2], [3]].flatMap { $0 }
print(a.count, b.count, c.count)Pick one
Higher-order functions
What does this code print?
let raw = ["1", "x", "3"]
let a = raw.map { Int($0) }
let b = raw.compactMap { Int($0) }
let c = [[1, 2], [3]].flatMap { $0 }
print(a.count, b.count, c.count)Pick one
SwiftShort answerAdvanced
Suppose there were no question-mark optional syntax and no standard Optional. If you had …
#map #flatmap
SwiftShort answerIntro
Take ["a", "b", "c"] as input and produce ["c-0", "b-1", "a-2"]. You can't use a for loop…
#map
SwiftShort answerBasics
Extend Array with a myCompactMap that behaves like the standard library's compactMap. How…
#compactmap
CS fundamentals and algorithmsShort answerAdvanced
You have tens of thousands of places with an id and coordinates (latitude, longitude). Gi…
#map