mirror of
https://github.com/janet-lang/janet
synced 2025-01-13 00:50:26 +00:00
Add frequencies to core library.
This commit is contained in:
parent
63baa52392
commit
6d1ab414e4
@ -1,11 +0,0 @@
|
|||||||
# 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 @{})
|
|
||||||
(loop
|
|
||||||
[x :in ind]
|
|
||||||
(def n (get freqs x))
|
|
||||||
(put freqs x (if n (+ 1 n) 1)))
|
|
||||||
freqs)
|
|
@ -730,6 +730,16 @@ in the same manner, and so on. Useful for expressing pipelines of data."
|
|||||||
(:= k (next x k)))
|
(:= k (next x k)))
|
||||||
arr)
|
arr)
|
||||||
|
|
||||||
|
(defn frequencies
|
||||||
|
"Get the number of occurences of each value in a indexed structure."
|
||||||
|
[ind]
|
||||||
|
(def freqs @{})
|
||||||
|
(loop
|
||||||
|
[x :in ind]
|
||||||
|
(def n (get freqs x))
|
||||||
|
(put freqs x (if n (+ 1 n) 1)))
|
||||||
|
freqs)
|
||||||
|
|
||||||
###
|
###
|
||||||
###
|
###
|
||||||
### Pretty Printer
|
### Pretty Printer
|
||||||
|
Loading…
Reference in New Issue
Block a user