Code Challenge 10/03/2018


#1

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.

Examples:

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.


#2

A Ruby implementation https://repl.it/@KevinMulhern/DarkcyanStableSalmon


#3

A Lua implementation https://repl.it/@ryanford_fronte/Word-Counter


#4

#5

A JS implementation: https://repl.it/@RukkiesMan/Most-Occurring-Words
It can be a very huge decision, but I’m still just learning :slightly_smiling_face:


#6

@RukkiesMan

Hey, thanks for contributing.

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


#7

@CouchofTomato

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


#8

A JS implementation

Enjoy


#9

Simple ruby implementation https://repl.it/@16S110Rainmaker/MostOccurrence

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


#10

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.