Horje
golang find nearest number to array Code Example
golang find nearest number to 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
	}
}




Go

Related
how to gab the users imput Code Example how to gab the users imput Code Example
array of channels golang Code Example array of channels golang Code Example
golang converts string to rune slice Code Example golang converts string to rune slice Code Example
run go file from terminal Code Example run go file from terminal Code Example
golang read large file Code Example golang read large file Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7