Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

ruby get the number of same element in array

names = ["Jason", "Jason", "Teresa", "Judah", "Michelle", "Judah", "Judah", "Allison"]
counts = names.each_with_object(Hash.new(0)){ |string, hash| hash[string] += 1 }
puts counts # => { Jason: 2, Teresa: 1, Judah: 3, ... }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #ruby #number #element #array
ADD COMMENT
Topic
Name
7+5 =