> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/s/sort_using_a_custom_comparator.md).

# Sort using a custom comparator

```ruby
func mycmp(a, b) { (b.len <=> a.len) || (a.lc <=> b.lc) }
var strings = %w(Here are some sample strings to be sorted)
var sorted = strings.sort(mycmp)
```
