Map, FlatMap, Reduce & More

Unique

Unique

Return a list with all duplicates removed. The better solution would be to use a Set.

[1, 2, 5, 1, 7].reduce([], { (a: [Int], b: Int) -> [Int] in
  if a.contains(b) {
    return a
  } else {
    return a + [b]
  }
})
// prints: 1, 2, 5, 7