mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
20 lines
346 B
Go
20 lines
346 B
Go
package strings
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// JoinWithConjunction joins a slice of strings with commas except for the last
|
|
// two which are joined with "and".
|
|
func JoinWithConjunction(s []string) string {
|
|
last := len(s) - 1
|
|
if last == 0 {
|
|
return s[last]
|
|
}
|
|
return fmt.Sprintf("%s and %s",
|
|
strings.Join(s[:last], ", "),
|
|
s[last],
|
|
)
|
|
}
|