update: slice exercises 23

This commit is contained in:
Inanc Gumus
2019-08-22 20:00:58 +03:00
parent ce5a32ecbe
commit 792a7a75d4
4 changed files with 38 additions and 65 deletions

View File

@ -1,24 +1,22 @@
package api
// The original temperatures slice.
var temps = []int{5, 10, 3, 25, 45, 80, 90}
// Read returns a range of temperature readings beginning from
// the `start` until to the `stop`.
// Read returns a slice of elements from the temps slice.
func Read(start, stop int) []int {
//
// This third index prevents the clients of this package from
// overwriting the original temps slice's backing array. It
// limits the capacity of the returned slice. See the
// full slice expressions lecture.
// ^
// |
// The third index prevents the `main()` from
// overwriting the original temps slice's
// backing array. It limits the capacity of the
// returned slice. See the full slice expressions
// lecture for more details.
//
portion := temps[start:stop:stop]
return portion
}
// All returns all the temperature readings
// All returns the temps slice
func All() []int {
return temps
}