Programming in Swift: Functions & Types

Jan 4 2022 · Swift 5.5, iOS 15, Xcode 13

Part 2: Closures

17. filter, reduce, & sort

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 16. Challenge: Closures & Collections Next episode: 18. Challenge: filter & reduce

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Notes: 17. filter, reduce, & sort

More About Algorithms

Update Notes: This course was originally recorded in 2019. It has been reviewed and all content and materials updated as of October 2021.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

This is the last episode that will focus on using closures and collections together, and here, we’ll tackle filter, reduce, and the sort methods.

dwarves.filter(<#T##isIncluded: (String) throws -> Bool##(String) throws -> Bool#>)  
  dwarves.filter { (<#String#>) -> Bool in
    <#code#>
  }
  dwarves.filter { (😺dwarf🛑) -> Bool in
    dwarf > "M"
  dwarves.filter { ❌(dwarf) -> Bool in❌
    dwarf > "M"
  }
dwarves.filter { $0 > "M" }
  var totalGrade = ❌0
  for grade in grades {
    totalGrade += grade
  }❌
var totalGrade = 😺grades.reduce(<#T##initialResult: Result##Result#>, <#T##nextPartialResult: (Result, Int) throws -> Result##(Result, Int) throws -> Result#>)
grades.reduce(😺0🛑) { 

}
let totalGrade = grades.reduce(0) { (<#Result#>, <#Int#>) -> Result in
    <#code#>
  }
grades.reduce(0) { 😺total, grade🛑 -> Result
grades.reduce(0) { total, grade -> 😺Int🛑 in
  total + grade
getPassStatus(for: ozmaGrades, lowestPass: 60)
  let totalGrade = grades.reduce(0, 😺+) //{ total, grade -> Int in
//    total + grade
//  }🛑
let stockSums = 
let stockSums = stock.reduce(into: <#T##Result#>, <#T##updateAccumulatingResult: (inout Result, (key: Double, value: Int)) throws -> ()##(inout Result, (key: Double, value: Int)) throws -> ()#>)
let stockSums = stock.reduce(into: 😺[]) { (<#inout Result#>, <#(key: Double, value: Int)#>) in
  <#code#>
}
let stockSums = stock.reduce(into: []) { (😺result, item🛑) in
  result.append(item.key * Double(item.value))
names.sort()
names.sort { (a, b) -> Bool in

}
  a > b
}
names
names.sort(by: >)
let longToShortNames = names.sorted {
  
}
let longToShortNames = names.sorted {
  $0.count > $1.count
}
longToShortNames
names
  dwarves.filter { $0 > "M" }
}.sorted()