From 541469371a6a95cb45cc608cf96a936282dfb76f Mon Sep 17 00:00:00 2001 From: primo-ppcg Date: Fri, 8 Sep 2023 11:35:37 +0700 Subject: [PATCH] update `mean` --- src/boot/boot.janet | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 93a2a393..0b7c0cb4 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -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."