0Pricing
Swift Academy · Lesson

Sorting, Searching and Slicing

sorted(), sort(), firstIndex(of:), prefix, suffix and ArraySlice.

Welcome

Swift arrays come with a rich set of algorithms for sorting, searching, and slicing. Learning them reduces hand-written loops and produces cleaner, faster code.

sorted() vs sort()

```swift let nums = [3,1,4,1,5,9] let sorted = nums.sorted() // new array, nums unchanged var mutable = [3,1,4] mutable.sort() // in-place sort ``` `sorted()` works on `let` arrays; `sort()` requires `var`.

All lessons in this course

  1. Creating and Mutating Arrays
  2. Sorting, Searching and Slicing
  3. Map, Filter and Reduce on Arrays
  4. 2D Arrays and Nested Collections
← Back to Swift Academy