TIL count takes a block
TIL Ruby’s Array#count can take a block. It returns the number of elements in the collection where the block returns true. It’s like saying “count the items where…” Pretty cool!
[1, 2, 3].count { |number| number > 2 }
#=> 1
TIL Ruby’s Array#count can take a block. It returns the number of elements in the collection where the block returns true. It’s like saying “count the items where…” Pretty cool!
[1, 2, 3].count { |number| number > 2 }
#=> 1