-
Notifications
You must be signed in to change notification settings - Fork 0
/
isvalid.go
65 lines (62 loc) · 1.52 KB
/
isvalid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package isvalid
// Criteria to pass, i.e. 1 to 9 is true
func isValidValue(a int) bool {
return a < 10
}
func isPositive(a int) bool {
return a > 0
}
func CheckValueFuncVar(test []int) (s []int) {
b := false // default value is assigned automatically
if b = isValidValue(test[0]); b && isPositive(test[0]) {
s = append(s, test[0])
}
if b = isValidValue(test[1]); b && isPositive(test[1]) {
s = append(s, test[1])
}
if b = isValidValue(test[2]); b && isPositive(test[2]) {
s = append(s, test[2])
}
if b = isValidValue(test[3]); b && isPositive(test[3]) {
s = append(s, test[3])
}
if b = isValidValue(test[4]); b && isPositive(test[4]) {
s = append(s, test[4])
}
return
}
func CheckValueIfVar(test []int) (s []int) {
if b := isValidValue(test[0]); b && isPositive(test[0]) {
s = append(s, test[0])
}
if b := isValidValue(test[1]); b && isPositive(test[1]) {
s = append(s, test[1])
}
if b := isValidValue(test[2]); b && isPositive(test[2]) {
s = append(s, test[2])
}
if b := isValidValue(test[3]); b && isPositive(test[3]) {
s = append(s, test[3])
}
if b := isValidValue(test[4]); b && isPositive(test[4]) {
s = append(s, test[4])
}
return
}
func CheckValueForFunc(test []int) (s []int) {
b := false // default value is assigned automatically
for _, v := range test {
if b = isValidValue(v); b && isPositive(v) {
s = append(s, v)
}
}
return
}
func CheckValueForIf(test []int) (s []int) {
for _, v := range test {
if b := isValidValue(v); b && isPositive(v) {
s = append(s, v)
}
}
return
}