1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-30 15:13:03 +00:00
Files
janet/examples/frequencies.dst
Calvin Rose 238cec8f32 Add each.
2018-05-05 14:41:47 -04:00

11 lines
259 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 @{})
(each (fn [x]
(let [n (get freqs x)]
(put freqs x (if n (+ 1 n) 1)))) ind)
freqs)