Lesson 19Sorting and Data Processing

In this lesson, a number of data-related topics will be covered. In previous lessons, you've imported and used packages, such as fmt to do printing and the time package to pause your program for a period of time. You'll dig into a number of other packages provided in Go and learn how to use them to do sorting, to work with dates and times, and to perform searches in strings with regular expressions.

SORTING

Go includes the sort package, which allows you to perform sorting operations on comparable data types such as numbers and strings. In Listing 19.1 you define a slice storing integers. You then use the Ints function from the sort package to sort the values in the slice.

In this listing, we use the sort package to execute the Ints function, which sorts the slice in ascending order. This is done by passing the name of the slice to the function:

sort.Ints(numbers)

Get Job Ready Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.