Ray Wenderlich Functions and Types Course - Part 5
No need for any pre text, let's go! The aim is to complete this chapter on closures today. Start Time - 17:05 Filter, Reduce and Sort So filter can be used - having certain criteria rather than the for loop! Xcode updating so following along without typing at the moment. Another example with grades. This is what we had before - // -------------------------------------- var stock = [ 1.50 : 5 , 10.00 : 2 , 4.99 : 20 , 2.30 : 5 , 8.19 : 30 ] // -------------------------------------- let stockSums = stock . reduce (into: []) { (result, item) in result. append (item.key * Double (item.value)) } So this is another use of reduce - complex stuff but good practice! You basically don't need to create your own sorting algorithms - this is what the closure does. Sort Sorting an array of strings - names . sort () names . sort { (a, b) -> Bool in a > b } name...