Kodewick
Start learning →
Mini challenge←→0 / 70

Child and adult tickets

#048Mini challengeFunctionsSlices5 min

The cinema splits the queue by age: under 12 buys a child ticket, everyone else an adult one. Write SplitAges(ages) to return two slices, the children's ages and the adults' ages, each in the original order. Nobody gives two empty slices.

Examples
SplitAges([]int{8, 35, 11, 40})→([8, 11], [35, 40])
SplitAges([]int{})→([], [])
The functionfunc SplitAges(ages []int) ([]int, []int)
main.go
package main

func SplitAges(ages []int) ([]int, []int) {
	kids := []int{}
	adults := []int{}
	// your code here: go through the ages: under 12 into kids, the rest into adults
	return kids, adults
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.