Add words even if empty, to prevent undersized lists
This commit is contained in:
parent
8192cf3315
commit
93610858d0
|
@ -22,27 +22,22 @@ func NewList(words []string) List {
|
|||
for _, w := range words {
|
||||
w = strings.TrimSpace(w)
|
||||
w = strings.ToUpper(w)
|
||||
if w != "" {
|
||||
cleaned = append(cleaned, w)
|
||||
}
|
||||
}
|
||||
return newList(cleaned)
|
||||
}
|
||||
|
||||
func NewListFromLines(s string) List {
|
||||
s = strings.TrimSpace(s)
|
||||
words := make([]string, 0, strings.Count(s, "\n"))
|
||||
|
||||
scanner := bufio.NewScanner(strings.NewReader(s))
|
||||
|
||||
for scanner.Scan() {
|
||||
word := scanner.Text()
|
||||
word = strings.TrimSpace(word)
|
||||
word = strings.ToUpper(word)
|
||||
|
||||
if word != "" {
|
||||
words = append(words, word)
|
||||
}
|
||||
}
|
||||
|
||||
return newList(words)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue