Skip to content

Instantly share code, notes, and snippets.

@marcosccm
Last active January 3, 2016 11:19
Show Gist options
  • Save marcosccm/8455338 to your computer and use it in GitHub Desktop.
Save marcosccm/8455338 to your computer and use it in GitHub Desktop.
get samples from an array n times and see each element appears more times
10.times.collect { ["clj", "blog", "pacto"].sample }.group_by { |x| x }.map { |k,v| [k,v.size] }.max_by { |x| x.last }
10.times.collect { ["clj", "blog", "pacto"].sample }.inject(Hash.new(0)) { |acc, elem| acc[elem] += 1; acc }.max_by { |k,v| v }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment