1
0
mirror of https://github.com/janet-lang/janet synced 2024-07-02 18:13:15 +00:00
janet/examples/frequencies.dst

11 lines
259 B
Plaintext
Raw Normal View History

2018-03-14 03:39:49 +00:00
# Get the number of occurences of elements in a set
(defn frequencies
2018-05-02 03:38:53 +00:00
"Get the number of occurences of each value in a indexed structure."
[ind]
(def freqs @{})
2018-05-05 18:41:47 +00:00
(each (fn [x]
2018-05-02 03:38:53 +00:00
(let [n (get freqs x)]
(put freqs x (if n (+ 1 n) 1)))) ind)
freqs)