Swift has a built-in
sort() method by using that we can sort an array both ascending and descending order.
var numbers = [3,54,1,5,2]; numbers.sort() // sorting print(numbers)
To sort an array in descending order we need to pass
by: > as an argument to the
var numbers = [3,54,1,5,2]; numbers.sort(by: >) // sorting descending order print(numbers)