Files
bootdotdev-fcc-learn-golang…/course/10-advanced_functions/exercises/5-closures/complete.go
wagslane 9be3074de6 first
2023-05-01 15:25:27 -06:00

51 lines
686 B
Go

package main
import "fmt"
func adder() func(int) int {
sum := 0
return func(x int) int {
sum += x
return sum
}
}
// don't touch below this line
type emailBill struct {
costInPennies int
}
func test(bills []emailBill) {
defer fmt.Println("====================================")
countAdder, costAdder := adder(), adder()
for _, bill := range bills {
fmt.Printf("You've sent %d emails and it has cost you %d cents\n", countAdder(1), costAdder(bill.costInPennies))
}
}
func main() {
test([]emailBill{
{45},
{32},
{43},
{12},
{34},
{54},
})
test([]emailBill{
{12},
{12},
{976},
{12},
{543},
})
test([]emailBill{
{743},
{13},
{8},
})
}