Created
August 8, 2022 07:13
-
-
Save jonahaung/7f8f8f09dc88102ef3703aa52d21667c to your computer and use it in GitHub Desktop.
This file contains 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
func bigSorting(unsorted: [String]) -> [String] { | |
let strings = unsorted.sorted { (left, right) -> Bool in | |
if left.count > right.count { | |
return false | |
} | |
if left.count < right.count { | |
return true | |
} | |
if let l = Int(left), let r = Int(right) { | |
if l > r { | |
return false | |
} else if l < r { | |
return true | |
} | |
} | |
for i in 0..<left.count { | |
let leftValue = left[left.index(left.startIndex, offsetBy: i)] | |
let rightValue = right[right.index(right.startIndex, offsetBy: i)] | |
if leftValue > rightValue { | |
return false | |
} else if leftValue < rightValue { | |
return true | |
} | |
} | |
return false | |
} | |
return strings | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment