JanetDocsPlaygroundI'm feeling luckyGitHub sign in

count



    function
    boot.janet on line 994, column 1

    (count pred ind)

    Count the number of items in `ind` for which `(pred item)` is true.


1 exampleSign in to add an example
Loading...
(count even? [1 2 3 4 5])  # => 2

(count  (fn [x] (> x 3))  [1 2 3 4 5])  # => 2
(count         |(> $ 3)   [1 2 3 4 5])  # => 2

(count  (fn [x] (truthy? x))  [nil false true 42 :a "foo"])  # => 4
(count         |(truthy? $)   [nil false true 42 :a "foo"])  # => 4

(var f even?)
(count f [1 2 3 4 5])  # => 2
(set f odd?)
(count f [1 2 3 4 5])  # => 3

(map  (fn [f] (count f [1 2 3 4 5]))  [even? odd?])  # => @[2 3]
(map         |(count $ [1 2 3 4 5])   [even? odd?])  # => @[2 3]
cellularmitosisPlayground