1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-08 01:39:55 +00:00
janet/lib/frequencies.dst
2018-03-13 23:39:49 -04:00

12 lines
283 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 @{}
fop (fn [x]
(let [n (get freqs x)]
(put freqs x (if n (+ 1 n) 1))))
_ (domap fop s)]
freqs))