Skip to content

Instantly share code, notes, and snippets.

@hassanshamim
Created July 11, 2013 21:29
Show Gist options
  • Select an option

  • Save hassanshamim/5979428 to your computer and use it in GitHub Desktop.

Select an option

Save hassanshamim/5979428 to your computer and use it in GitHub Desktop.
Linq thing
def top10(str)
word_dict = Hash.new{|hash, key| hash[key] = 0 }
str.split.each{ |word| word_dict[word] += 1 }
word_dict.to_a.sort{|a, b| b.last <=> a.last }.take(10).map(&:first) #ugly ugly
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment