Created
July 12, 2020 22:36
-
-
Save Coollision/4d9dd0e7f5796f2fba2ac2b49069d80c to your computer and use it in GitHub Desktop.
GOLANG Introduction into Testing: basic main file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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