Golang finden die nächste Nummer zu Array
func find(numbers []int, goal int) []int {
n := []int{}
for i, num := range numbers {
if int(i+1) < len(numbers) {
if math.Abs(float64(numbers[i+1]-goal)) < math.Abs(float64(num-goal)) {
n = append(n, numbers[i+1])
} else {
n = append(n, num)
}
}
}
if len(n) > 1 {
return find(n, goal)
} else {
return n
}
}
Long Lizard