about summary refs log tree commit diff
path: root/users/glittershark/emacs.d/utils.el
diff options
context:
space:
mode:
authorGriffin Smith <grfn@gws.fyi>2020-07-20T14·48-0400
committerglittershark <grfn@gws.fyi>2020-07-20T15·51+0000
commita89c2f9bd895ae08093fcd137abf2a3c93b53df7 (patch)
treef48726ec769b2d487491844a18942ddd48a9431d /users/glittershark/emacs.d/utils.el
parent17ca547ed34082803c718859177e81464f8a1f3c (diff)
feat(gs/emacs): Add an "average" util function r/1410
I've been using this in some literate org scripts lately

Change-Id: I42830fb30dd77c9b04fcc9373cafcef05fa8b837
Reviewed-on: https://cl.tvl.fyi/c/depot/+/1322
Tested-by: BuildkiteCI
Reviewed-by: glittershark <grfn@gws.fyi>
Diffstat (limited to 'users/glittershark/emacs.d/utils.el')
-rw-r--r--users/glittershark/emacs.d/utils.el9
1 files changed, 9 insertions, 0 deletions
diff --git a/users/glittershark/emacs.d/utils.el b/users/glittershark/emacs.d/utils.el
index c595b46ce258..1bfac3ca8b33 100644
--- a/users/glittershark/emacs.d/utils.el
+++ b/users/glittershark/emacs.d/utils.el
@@ -10,6 +10,15 @@
 (defun inc (x) "Returns x + 1" (+ 1 x))
 (defun dec (x) "Returns x - 1" (- x 1))
 
+(defun average (ns)
+  "Arithmetic mean of xs"
+  (if (null ns) nil
+    (/ (apply #'+ ns)
+       (length ns))))
+
+(comment
+ (average (list 1 2 3 4))
+ )
 
 ;;
 ;; Text editing utils