Skip to content

Instantly share code, notes, and snippets.

@hossamghareeb
Created September 20, 2018 06:00
Show Gist options
  • Save hossamghareeb/87421f7bbf90eef4334fd9dc3ab19f7d to your computer and use it in GitHub Desktop.
Save hossamghareeb/87421f7bbf90eef4334fd9dc3ab19f7d to your computer and use it in GitHub Desktop.
Partition in Swift
var arr = [1, 2, 5, 5, 6, 7, 10]
let pivot = arr.partition { $0 % 2 == 0 }
arr // [1, 7, 5, 5, 6, 2, 10]
let part1 = arr[..<pivot] // odd numbers
let part2 = arr[pivot...] // even numbers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment