Created
April 9, 2016 23:14
-
-
Save asm-jaime/6b9352592b423248297b5c47624be748 to your computer and use it in GitHub Desktop.
golang, make sequence of array
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" | |
"strconv" | |
) | |
const num int = 5 | |
func main() { | |
fmt.Print("\n") | |
fmt.Print(*sequence_int(num)) | |
fmt.Print(*sequence_str(num)) | |
} | |
func sequence_int(num int) *[]int { | |
seq := make([]int, num) | |
for i := 0; i < num; i++ { | |
seq[i] = i | |
} | |
return &seq | |
} | |
func sequence_str(num int) *[]string { | |
seq := make([]string, num) | |
for i := 0; i < num; i++ { | |
seq[i] = strconv.Itoa(i) | |
} | |
return &seq | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment