1
0
mirror of https://github.com/janet-lang/janet synced 2024-10-01 00:10:40 +00:00
janet/examples/frequencies.dst
2018-05-01 23:38:53 -04:00

11 lines
258 B
Plaintext

# Get the number of occurences of elements in a set
(defn frequencies
"Get the number of occurences of each value in a indexed structure."
[ind]
(def freqs @{})
(map (fn [x]
(let [n (get freqs x)]
(put freqs x (if n (+ 1 n) 1)))) ind)
freqs)