mirror of https://github.com/01-edu/public.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.2 KiB
75 lines
1.2 KiB
5 years ago
|
package main
|
||
5 years ago
|
|
||
|
import (
|
||
5 years ago
|
"../common"
|
||
5 years ago
|
"./student"
|
||
5 years ago
|
)
|
||
|
|
||
5 years ago
|
func countIf(f func(string) bool, arr []string) int {
|
||
|
counter := 0
|
||
|
for _, el := range arr {
|
||
|
if f(el) {
|
||
|
counter++
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return counter
|
||
|
}
|
||
|
|
||
5 years ago
|
func main() {
|
||
5 years ago
|
functions := []func(string) bool{common.IsNumeric, common.IsLower, common.IsUpper}
|
||
5 years ago
|
|
||
|
type node struct {
|
||
|
f func(string) bool
|
||
|
arr []string
|
||
|
}
|
||
|
|
||
|
table := []node{}
|
||
|
|
||
|
for i := 0; i < 5; i++ {
|
||
5 years ago
|
function := functions[lib.RandIntBetween(0, len(functions)-1)]
|
||
5 years ago
|
val := node{
|
||
5 years ago
|
f: function,
|
||
5 years ago
|
arr: lib.MultRandWords(),
|
||
5 years ago
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
for i := 0; i < 5; i++ {
|
||
|
val := node{
|
||
5 years ago
|
f: common.IsNumeric,
|
||
5 years ago
|
arr: lib.MultRandDigit(),
|
||
5 years ago
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
|
||
|
for i := 0; i < 5; i++ {
|
||
|
val := node{
|
||
5 years ago
|
f: common.IsLower,
|
||
5 years ago
|
arr: lib.MultRandLower(),
|
||
5 years ago
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
for i := 0; i < 5; i++ {
|
||
|
val := node{
|
||
5 years ago
|
f: common.IsUpper,
|
||
5 years ago
|
arr: lib.MultRandUpper(),
|
||
5 years ago
|
}
|
||
|
table = append(table, val)
|
||
|
}
|
||
|
|
||
|
table = append(table,
|
||
|
node{
|
||
5 years ago
|
f: common.IsNumeric,
|
||
5 years ago
|
arr: []string{"Hello", "how", "are", "you"},
|
||
|
},
|
||
|
node{
|
||
5 years ago
|
f: common.IsNumeric,
|
||
5 years ago
|
arr: []string{"This", "is", "4", "you"},
|
||
|
},
|
||
|
)
|
||
|
|
||
|
for _, arg := range table {
|
||
5 years ago
|
lib.Challenge("CountIf", student.CountIf, countIf, arg.f, arg.arr)
|
||
5 years ago
|
}
|
||
|
}
|