Created
September 25, 2020 10:15
-
-
Save shemul/7aff4b09e250f5b4ea30457bb099a823 to your computer and use it in GitHub Desktop.
golang generic example
This file contains hidden or 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 reverse(arr []interface{}) interface{} { | |
var i = 0 | |
var j = len(arr) - 1 | |
for i < j { | |
tmp := arr[i] | |
arr[i] = arr[j] | |
arr[j] = tmp | |
i++ | |
j-- | |
} | |
return arr | |
} | |
func main() { | |
fmt.Println(reverse([]interface{}{"a","b","c"})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment