3 ms·
Alternative approach depending on preferred readability: STDIN.each .map(&:downcase) .map(&:split) .flatten .tally
by petercooper 6y ago
Alternative approach depending on preferred readability:
STDIN.each
.map(&:downcase)
.map(&:split)
.flatten
.tally
.sort_by { _2 }
.reverse
.each { |word, count| puts "#{word} #{count}" }
(It has a slightly different performance profile and is slightly slower than the other implementation. 477ms vs 418ms on the KJV dataset for me.)