Averages/Mode: Difference between revisions
Content added Content deleted
(Added AppleScript.) |
Thundergnat (talk | contribs) m (Regularize non-standard header markup) |
||
Line 566: | Line 566: | ||
(->> coll frequencies (sort-by val >) (partition-by val) first (map key)))</lang> |
(->> coll frequencies (sort-by val >) (partition-by val) first (map key)))</lang> |
||
== |
=={{header|CoffeeScript}}== |
||
<lang coffeescript>mode = (arr) -> |
<lang coffeescript>mode = (arr) -> |
||
# returns an array with the modes of arr, i.e. the |
# returns an array with the modes of arr, i.e. the |
||
Line 581: | Line 581: | ||
console.log mode [1, 2, 2, 2, 3, 3, 3, 4, 4]</lang> |
console.log mode [1, 2, 2, 2, 3, 3, 3, 4, 4]</lang> |
||
== |
=={{header|Common Lisp}}== |
||
The following returns a list of the modes of a sequence as the primary value, and the frequency as the secondary value. E.g., <code>(mode '(a b c d a b c a b))</code> produces <code>(A B)</code> and <code>3</code>. hash-table-options can be used to customize the hash table, e.g., to specify the test by which elements are compared. |
The following returns a list of the modes of a sequence as the primary value, and the frequency as the secondary value. E.g., <code>(mode '(a b c d a b c a b))</code> produces <code>(A B)</code> and <code>3</code>. hash-table-options can be used to customize the hash table, e.g., to specify the test by which elements are compared. |
||
<lang lisp>(defun mode (sequence &rest hash-table-options) |
<lang lisp>(defun mode (sequence &rest hash-table-options) |