From the course: Code Clinic: Swift

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Write mean and median methods

Write mean and median methods - Swift Tutorial

From the course: Code Clinic: Swift

Start my 1-month free trial

Write mean and median methods

- [Instructor] Now let's look at actually calculating the mean and median values that we need to present to show the user the appropriate data for the query that they've created. So we'll start by creating a new method above showMessage, and we'll call this findAverages. And it's going to receive the data from our query. So we'll have that be an unnamed parameter. We'll name it data. And the type is going to be results and then day data in the less than and greater than signs. So this is a list of day data objects. We'll add some curly braces and there we have the method. So we're going to call that method at the bottom of update days. So down here call findAverages, pass in our data and now we're ready to start setting that up. So what we need here are arrays of doubles for the temperatures, speeds, and the pressures. So I'm going to create that in here. So var, call this temps. Data type is an array of doubles. We'll initialize it to an empty array. We'll do the same thing for…

Contents