1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 11:09:54 +00:00
janet/examples/frequencies.dst
Calvin Rose 73ead5c2de Update core namespace. Clean up some code,
and put more emphasis on indexed data-structure combinators
instead of iterators.
2018-03-28 13:58:56 -04:00

13 lines
307 B
Plaintext

# Get the number of occurences of elements in a set
(import "examples/iterators.dst")
(defn frequencies
"Get the number of occurences of each value in a sequence."
[s]
(let [freqs @{}
_ (foreach s (fn [x]
(let [n (get freqs x)]
(put freqs x (if n (+ 1 n) 1)))))]
freqs))