Created
June 12, 2017 22:11
-
-
Save GottaGetSwifty/d53b9c07158d92b59ab14512dc2275d0 to your computer and use it in GitHub Desktop.
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 myArray: [[String]] = [ | |
| ["1", "picture1.png", "John", "Smith"], | |
| ["2", "picture2.png", "Mike", "Rutherford"], | |
| ] | |
| func sort<T: Comparable>(ArrayOfArrays: [[T]], sortingIndex: Int, sortFunc: (T, T) -> Bool) -> [[T]] { | |
| return ArrayOfArrays.sorted { sortFunc($0[sortingIndex], $1[sortingIndex])} | |
| } | |
| print(sort(ArrayOfArrays: myArray, sortingIndex: 0, sortFunc: <)) | |
| //[["1", "picture1.png", "John", "Smith"], ["2", "picture2.png", "Mike", "Rutherford"]] | |
| print(sort(ArrayOfArrays: myArray, sortingIndex: 0, sortFunc: >)) | |
| //[["2", "picture2.png", "Mike", "Rutherford"], ["1", "picture1.png", "John", "Smith"]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment