Kodewick
Start learning →
Basic←→0 / 70

Win-loss record

#046BasicFunctionsStrings4 min

A team's record is a string of letters: W win, L loss, D draw. Write WinsLosses(games) to return the wins and the losses at once (draws don't count). An empty string gives 0, 0.

Examples
WinsLosses("WLWD")→(2, 1)
WinsLosses("")→(0, 0)
The functionfunc WinsLosses(games string) (int, int)
main.go
package main

func WinsLosses(games string) (int, int) {
	wins, losses := 0, 0
	for _, g := range games {
		// your code here: 'W' adds 1 to wins, 'L' adds 1 to losses
	}
	return wins, losses
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.