Tip This example reverses an array, not a string, because we converted the string to an array before reversing it.
letters = "cat"
# Get letters from string with split.# ... Then sort, and reverse, the letters.# ... Finally join them back together into a string.
result = letters.split("").sort.reverse.join()
A summary. In sorting, we can sometimes apply a descending (high-to-low) sort instead of invoking reverse(). But if we are not sorting, reverse() can be directly called.
Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.
Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.