-
Notifications
You must be signed in to change notification settings - Fork 0
/
gcf.go
40 lines (29 loc) · 824 Bytes
/
gcf.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
package golist
import (
"github.com/emylincon/golist/core"
)
// GCF :
// returns greatest common factor of the list. returns error if type of list is string or any of the unsupported types
func (arr *List) GCF() (gcf interface{}, err error) {
switch list := arr.list.(type) {
case []int:
return core.GCFInt(&list)
case []int32:
return core.GCFInt32(&list)
case []int64:
return core.GCFInt64(&list)
case []float32:
return core.GCFFloat32(&list)
case []float64:
return core.GCFFloat64(&list)
case []string:
return nil, ErrStringsNotsupported
default:
return nil, ErrTypeNotsupported
}
}
// HCF :
// returns greatest common factor of the list. returns error if type of list is string or any of the unsupported types
func (arr *List) HCF() (gcf interface{}, err error) {
return arr.GCF()
}