1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-18 06:34:48 +00:00
janet/examples/frequencies.dst

11 lines
272 B
Plaintext

# Get the number of occurences of elements in a set
(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))