mirror of
https://github.com/janet-lang/janet
synced 2024-12-26 00:10:27 +00:00
update mean
This commit is contained in:
parent
a13aeaf955
commit
541469371a
@ -643,7 +643,12 @@
|
||||
(defn mean
|
||||
"Returns the mean of xs. If empty, returns NaN."
|
||||
[xs]
|
||||
(/ (sum xs) (length xs)))
|
||||
(if (lengthable? xs)
|
||||
(/ (sum xs) (length xs))
|
||||
(do
|
||||
(var [accum total] [0 0])
|
||||
(each x xs (+= accum x) (++ total))
|
||||
(/ accum total))))
|
||||
|
||||
(defn product
|
||||
"Returns the product of xs. If xs is empty, returns 1."
|
||||
|
Loading…
Reference in New Issue
Block a user