Code Challenge 10/03/2018


Write a function that takes a string as an argument. The function should return an array of the top 3 occurring words in the string in descending order.

If the string contains fewer than 3 unique words then just return the unique words that you have in descending order of appearance.

Matches should be case-insensitive and an empty array should be returned if the string is empty.


input: 'a a a a b b b c c d'
output: ['a', 'b', 'c']

input: 'hey friend, it's great to see a friend. I wish I had another friend like you. What a friend'
output ['friend', 'a', 'I']

Tests are encouraged. The function can be written in any language you are comfortable with.


A Ruby implementation


A Lua implementation



A JS implementation:
It can be a very huge decision, but I’m still just learning :slightly_smiling_face:



Hey, thanks for contributing.

I’m also working on a JS implementation as that’s my weakest language so will check yours out after.



Cool, if you have something that is not clear in my code, then write me :wink:


A JS implementation



Simple ruby implementation

I think I should learn the Object Orientation Programming to solve problems. Like KevinMulhern’s answer.


Hey @Ding-Fan

Thanks for submitting a solution. These challenges are a good way to explore different approaches whether object orientated or functional so do play around with it.

Ruby is an object orientated language though so you would benefit from learning OOP principles.