The sorted()
method in Swift, when invoked on a sequence or array, returns the elements of the sequence in a sorted order.
sequence.sorted()
This method does not take any parameters.
This method returns the elements of the sequence in a sorted order.
// create arraysvar arr1 = [3, 4, 1]var arr2 = ["c", "e", "b", "d", "a"]var arr3 = [-3, 0.3, -1.1]// print sorted arraysprint(arr1.sorted())print(arr2.sorted())print(arr3.sorted())
sorted()
method on the arrays. Then, we print the results to the console.