From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Arrays with map, filter, and reduce

Arrays with map, filter, and reduce

From the course: iOS Development Tips

Arrays with map, filter, and reduce

- [Instructor] There are three methods for arrays that, while meant for functional programming, work well in a lot of contexts. The map, filter, and reduced methods of arrays might make your work a lot easier. Let's take a look at them. I've put together a copy of my favorite menu in a playground, and a small array of Double to show how these work. These methods have a similar form of a method with a closure inside. Now I'm going to start with the map. Map makes an array, giving the value of each element which will use the closure shortcut of $0 for. You can then compute some values off of $0 in the closure. For example, an array of thin crust pizza volumes from diameters could be something like this where I could do var pizzaVolumes equals pizzaSizes.map and then I put the closure of $0/2.0 for division, and then I'll divide it again so I get the correct square. I'll divide by pi and 0.25. And I can run that.…

Contents