Skip to content

Instantly share code, notes, and snippets.

@jonahaung
Created August 8, 2022 07:13
Show Gist options
  • Save jonahaung/7f8f8f09dc88102ef3703aa52d21667c to your computer and use it in GitHub Desktop.
Save jonahaung/7f8f8f09dc88102ef3703aa52d21667c to your computer and use it in GitHub Desktop.
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