From the course: Learning Julia

Unlock the full course today

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

Sorting data

Sorting data - Julia Tutorial

From the course: Learning Julia

Start my 1-month free trial

Sorting data

- [Narrator] All right, let's wrap up this chapter by taking a closer look at how to sort various kinds of data in Julia. So I'm going to open up my Sort Start file. And you can see here I've already got some data defined. And these numbers are clearly in a random order. So to sort data, we use the sort function. And I can supply a transformation function that gets applied to each item during the sort process. So let's go ahead and see a simple example. I can sort this information by using the sort function. And I'm going use the version of sort that does not have the exclamation point. It's going to return a new sorted array. So I'll sort array one. And then I can use the by parameter to specify that I want to apply a transformation function to each item in the array. In this case, I'll just simply apply absolute value to each one of these guys. So this will become a positive three, this will be positive 15 and so on. And then I can just print the result. Okay, so that's a good point…

Contents