Skip to content

Commit

Permalink
feat: add len and reverse slice
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Dec 3, 2024
1 parent 7a8e855 commit 7a3b4c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions conv/conv.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ func String(val any) string {
return fmt.Sprintf("%d", val)
case float32, float64:
return fmt.Sprintf("%f", val)
case []byte:
return string(val)
case string:
return val
case nil:
Expand Down
15 changes: 15 additions & 0 deletions slices/slices.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,18 @@ func Size[T any](size int, slice ...T) bool {
func Append[T any](slice []T, elements ...T) []T {
return append(slice, elements...)
}

// Len returns the length of a slice.
func Len[T any](slice []T) int {
return len(slice)
}

// Reverse reverses the order of elements in a slice.
func Reverse[T any](slice []T) []T {
for i := len(slice)/2 - 1; i >= 0; i-- {
opp := len(slice) - 1 - i
slice[i], slice[opp] = slice[opp], slice[i]
}

return slice
}

0 comments on commit 7a3b4c3

Please sign in to comment.