lengths has each song's length in seconds, and fits is a function: give it one song's length and it says whether that song fits (true / false). Write CountSongs(lengths, fits) to return how many songs fit.
CountSongs([]int{180, 240, 300}, func(n int) bool { return n <= 240 })→2CountSongs([]int{}, func(n int) bool { return n <= 240 })→0func CountSongs(lengths []int, fits func(int) bool) intpackage main
func CountSongs(lengths []int, fits func(int) bool) int {
count := 0
for _, s := range lengths {
// your code here: if fits says this song fits, add 1 to count
}
return count
}
Run tries the examples. When they look right, Submit.