Mastering macOS Programming
上QQ阅读APP看书,第一时间看更新

Sorting arrays

The sort methods available on arrays come in two flavors:

The sorted method returns a new, sorted array:

var randomInts = [233, 6, 85, 1, 6, 24] 
let sortedInt = randomInts.sorted()
print(randomInts) //unchanged

The sort method mutates the array in place:

randomInts.sort()  
print(randomInts) //mutated