iOS ● ● ○ Swift 6

Kodebits Day 15: Filter Then Sort

May 1 2026
Chain collection operations to transform an array concisely.

What does this print?

let nums = [4, 1, 3, 1]
let out = nums
  .filter { $0 > 1 }
  .sorted()
print(out)


Try it in the online Swift Playground →

[spoiler title="Solution"]

Answer:

[3, 4]

Explanation:

filter removes 1s leaving [4, 3], then sorted orders the remaining values ascending.

[/spoiler]


Further Reading