Try it
Paste some text. The statistics below are computed by a Soli controller, inside the Worker that answered this request.
18 words
12 distinct
85 characters
4.7s to read
Most frequent
fast× 3soli× 2the× 2edge× 2is× 2
Longest word: close
The code
words = text.downcase.split(" ")
.map { |w| w.gsub("[^a-z0-9'-]", "") }
.filter { |w| w.length > 0 }
counts = {}
words.each do |w|
counts[w] = (counts[w] ?? 0) + 1
end
top = counts.keys.sort_by { |w| -counts[w] }.take(5)