Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# go-utils

<a name="v1.41.0"></a>
## [v1.41.0] - 2025-09-11
### New Features
- reverse slice


<a name="v1.40.2"></a>
## [v1.40.2] - 2025-06-10
### Fixes
- handle space on node link ([#70](https://github.com/kumparan/go-utils/issues/70))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mav mav



<a name="v1.40.1"></a>
## [v1.40.1] - 2025-04-24
### Fixes
- force jpeg on push notif image for better compression
- force jpeg on push notif image for better compression ([#69](https://github.com/kumparan/go-utils/issues/69))


<a name="v1.40.0"></a>
Expand Down Expand Up @@ -363,7 +375,9 @@
- init go-utils


[Unreleased]: https://github.com/kumparan/go-utils/compare/v1.40.1...HEAD
[Unreleased]: https://github.com/kumparan/go-utils/compare/v1.41.0...HEAD
[v1.41.0]: https://github.com/kumparan/go-utils/compare/v1.40.2...v1.41.0
[v1.40.2]: https://github.com/kumparan/go-utils/compare/v1.40.1...v1.40.2
[v1.40.1]: https://github.com/kumparan/go-utils/compare/v1.40.0...v1.40.1
[v1.40.0]: https://github.com/kumparan/go-utils/compare/v1.39.6...v1.40.0
[v1.39.6]: https://github.com/kumparan/go-utils/compare/v1.39.5...v1.39.6
Expand Down
9 changes: 9 additions & 0 deletions slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,12 @@ func ConvertSlice[T1 any, T2 any](in []T1, converter func(T1) T2) []T2 {
}
return res
}

// ReverseSlice :nodoc:
func ReverseSlice[T any](in []T) []T {
reversed := make([]T, 0)
for i := len(in) - 1; i >= 0; i-- {
reversed = append(reversed, in[i])
}
return reversed
}
14 changes: 14 additions & 0 deletions slice_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,17 @@ func Test_ConvertSliceType(t *testing.T) {
assert.Equal(t, dstSlice, ConvertSlice(srcSlice, strings.TrimSpace))
})
}

func Test_ReverseSlice(t *testing.T) {
t.Run("success", func(t *testing.T) {
source := []int{1, 2, 3, 4, 5}
dest := []int{5, 4, 3, 2, 1}
assert.Equal(t, dest, ReverseSlice(source))
})

t.Run("empty slice", func(t *testing.T) {
source := []int{}
dest := []int{}
assert.Equal(t, dest, ReverseSlice(source))
})
}