Files
learngo/16-slices/exercises/23-limit-the-backing-array-sharing/api/api.go

33 lines
875 B
Go
Raw Normal View History

2019-03-04 20:30:18 +03:00
package api
2019-08-18 12:59:50 +03:00
// note: "client" means the users or importers of your package.
// The original temperatures slice.
2019-03-04 20:30:18 +03:00
var temps = []int{5, 10, 3, 25, 45, 80, 90}
2019-08-18 12:59:50 +03:00
// ^ ^ ^ ^ ^
// | | | +-----------+
// the client is allowed to |
// change these elements. |
// |
// but the client shouldn't change the
// rest of the elements after the 3rd element.
2019-03-04 20:30:18 +03:00
// Read returns a range of temperature readings beginning from
// the `start` until to the `stop`.
func Read(start, stop int) []int {
// ----------------------------------------
// RESTRICTIONS — ONLY ADD YOUR CODE HERE
2019-08-18 12:59:50 +03:00
// returns a slice from the temps slice to the client.
2019-03-04 20:30:18 +03:00
portion := temps[start:stop]
// ----------------------------------------
return portion
}
// All returns all the temperature readings
func All() []int {
return temps
}