Skip to content

Instantly share code, notes, and snippets.

@Coollision
Created July 12, 2020 22:36
Show Gist options
  • Save Coollision/4d9dd0e7f5796f2fba2ac2b49069d80c to your computer and use it in GitHub Desktop.
Save Coollision/4d9dd0e7f5796f2fba2ac2b49069d80c to your computer and use it in GitHub Desktop.
GOLANG Introduction into Testing: basic main file
package main
import "fmt"
func main() {
list := []int{1, 2, 3, 3, 8, 4, 5}
lastIndexOfFive := LastIndex(list, 5)
fmt.Printf("the last index of %d in the list %v is: %d",
5, list, lastIndexOfFive)
}
func lastIndex(list []int, x int) int {
for i := len(list) - 1; i >= 0; i-- {
if list[i] == x {
return i
}
}
return -1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment