Count Occurrences in Ruby
Ruby has a new-ish method to count occurrences in an array. So since ruby 2.7.0 you can use the Enum tally to do:
["a", "b", "c", "b"].tally
# => {"a"=>1, "b"=>2, "c"=>1}
Here's a similar function in Elixir
TweetRuby has a new-ish method to count occurrences in an array. So since ruby 2.7.0 you can use the Enum tally to do:
["a", "b", "c", "b"].tally
# => {"a"=>1, "b"=>2, "c"=>1}
Here's a similar function in Elixir
Tweet