Kodewick
Start learning →
Basic←→0 / 70

Where did it go?

#041BasicMapsSlices4 min

A pocket-money diary: kinds[i] is what entry i was spent on and amounts[i] is how much; both slices are the same length. Write SpendByKind(kinds, amounts) to return the total spent on each kind.

Examples
SpendByKind([]string{"snack", "bus", "snack"}, []int{5, 2, 3})→{'bus': 2, 'snack': 8}
SpendByKind([]string{}, []int{})→{}
The functionfunc SpendByKind(kinds []string, amounts []int) map[string]int
main.go
package main

func SpendByKind(kinds []string, amounts []int) map[string]int {
	total := map[string]int{}
	for i, k := range kinds {
		// your code here: add entry i's amount to its kind
	}
	return total
}
Ctrl + Enter runs too
Result

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