MCPcopy Create free account
hub / github.com/couchbaselabs/cbgb / javascriptReduceCount

Function javascriptReduceCount

reduction.go:46–70  ·  view source on GitHub ↗
(call otto.FunctionCall)

Source from the content-addressed store, hash-verified

44}
45
46func javascriptReduceCount(call otto.FunctionCall) otto.Value {
47 rere, err := call.Argument(2).ToBoolean()
48 if err != nil {
49 return ottoMust(otto.ToValue(fmt.Sprintf("Error getting rere flag: %v", err)))
50 }
51
52 ob, err := call.Argument(1).Export()
53 if err != nil {
54 return ottoMust(otto.ToValue(fmt.Sprintf("Error getting stuff: %v", err)))
55 }
56 l, ok := ob.([]interface{})
57 if !ok {
58 return ottoMust(otto.ToValue(fmt.Sprintf("unhandled %v/%T", ob, ob)))
59 }
60
61 if !rere {
62 return ottoMust(otto.ToValue(len(l)))
63 }
64
65 rv := float64(0)
66 for _, i := range l {
67 rv += zeroate(i)
68 }
69 return ottoMust(otto.ToValue(rv))
70}
71
72type statsResult struct {
73 sum, min, max, sumsqr float64

Callers

nothing calls this directly

Calls 2

ottoMustFunction · 0.85
zeroateFunction · 0.85

Tested by

no test coverage detected