Add enumerate
This commit is contained in:
parent
9447daed1d
commit
d42862a485
@ -75,3 +75,12 @@ func Range(args...int) ([]int) {
|
|||||||
}
|
}
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Enumerate(iter interface{}) interface{} {
|
||||||
|
viter := reflect.ValueOf(iter)
|
||||||
|
enum := make([][]interface{}, viter.Len())
|
||||||
|
for i:=0; i < viter.Len(); i++ {
|
||||||
|
enum[i] = []interface{}{i, viter.Index(i).Interface()}
|
||||||
|
}
|
||||||
|
return enum
|
||||||
|
}
|
||||||
|
1
test.go
1
test.go
@ -22,6 +22,7 @@ func main(){
|
|||||||
Min([]float64{3.14159, 23.14069, 2.71828}),
|
Min([]float64{3.14159, 23.14069, 2.71828}),
|
||||||
Max(-3,24,1,-23,31),
|
Max(-3,24,1,-23,31),
|
||||||
Join(", ", []interface{}{2, -2.33, true, "hi"}),
|
Join(", ", []interface{}{2, -2.33, true, "hi"}),
|
||||||
|
Enumerate([]int{1, 1, 2, 42, 24024, 701149020}),
|
||||||
Input("Say hi! "),
|
Input("Say hi! "),
|
||||||
}
|
}
|
||||||
fmt.Println(Join("\n",test))
|
fmt.Println(Join("\n",test))
|
||||||
|
Loading…
Reference in New Issue
Block a user