astaphobia
12/13/2018 - 2:17 AM

find smallest number from array / slices of int using Golang

find smallest number from array / slices of int using Golang

package main

import (
	"fmt"
)

func main() {
	var (
		smallest int
	)
	x := []int{
		48, 96, 86, 68,
		57, 82, 63, 70,
		37, 34, 83, 27,
		19, 97, 17, 9,
	}
	for i := 0; i < len(x); i++ {
		if i < len(x)-1 {
			if x[i] < x[i+1] {
				smallest = x[i]
			}
		} else {
			if smallest > x[i] {
				smallest = x[i]
			}
		}
	}
	fmt.Println(smallest)
}