joinList joins items the way the prompt reads them: "a", "a and b", or "a, b, and c".
(items []string)
| 204 | // joinList joins items the way the prompt reads them: "a", "a and b", or |
| 205 | // "a, b, and c". |
| 206 | func joinList(items []string) string { |
| 207 | switch len(items) { |
| 208 | case 0, 1: |
| 209 | return strings.Join(items, "") |
| 210 | case 2: |
| 211 | return items[0] + " and " + items[1] |
| 212 | } |
| 213 | return strings.Join(items[:len(items)-1], ", ") + ", and " + items[len(items)-1] |
| 214 | } |
no test coverage detected