Browse Source

fixed-comma

drhodes 13 năm trước cách đây
mục cha
commit
1a630a3d72
1 tập tin đã thay đổi với 5 bổ sung3 xóa
  1. 5 3
      lorem.go

+ 5 - 3
lorem.go

@@ -89,13 +89,15 @@ func Sentence(min, max int) string {
 	maxcommas := 2
 	numcomma := 0
 	for i := 0; i < n; i++ {
-		// maybe insert a comma, if there's less than two and
+		ws = append(ws, (word(genWordLen())))
+
+		// maybe insert a comma, if there are currently < 2 commas, and
 		// the current word is not the last or first
 		if (src.Int()%n == 0) && numcomma < maxcommas && i < n-1 && i > 2 {
-			ws[len(ws)-1] += ","
+			ws[i-1] += ","
 			numcomma += 1
 		}
-		ws = append(ws, (word(genWordLen())))
+
 	}
 
 	sentence := strings.Join(ws, " ") + "."