Skip to content

Commit

Permalink
🧹 chore: improve padStart function
Browse files Browse the repository at this point in the history
  • Loading branch information
jingyuexing committed Jan 30, 2024
1 parent d6d1edd commit 635e86c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ func PadStart[T any](slice []T, targetLength int, padValue T) []T {
if paddingLength <= 0 {
return slice
}
if currentLength > targetLength {
return slice
}

newSlice := make([]T, 0, paddingLength)
for i := 0; i < paddingLength; i++ {
Expand Down

0 comments on commit 635e86c

Please sign in to comment.