Created
September 20, 2018 06:00
-
-
Save hossamghareeb/87421f7bbf90eef4334fd9dc3ab19f7d to your computer and use it in GitHub Desktop.
Partition in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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