Skip to content

Instantly share code, notes, and snippets.

@kjk kjk/main.go
Last active Nov 10, 2019

Embed
What would you like to do?
trimEmptyLinesFromEnd (made with https://codeeval.dev)
package main
import (
"fmt"
"strings"
)
func trimEmptyLinesFromEnd(a []string) []string {
for len(a) > 0 {
lastIdx := len(a) - 1
s := strings.TrimSpace(a[lastIdx])
if len(s) > 0 {
return a
}
a = a[:lastIdx]
}
return a
}
func main() {
a := []string{"a", "b", "", ""}
fmt.Printf("before: %#v\n", a)
a = trimEmptyLinesFromEnd(a)
fmt.Printf("after: %#v\n", a)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.