WORD COUNT ENGINE is a medium difficulty coding challenge that I found on PRAMP. Test your profficiency with strings and arrays.
Implement a document scanning function wordCountEngine
which receives a string document
and returns a list of all unique words in it and their number of occurrences, sorted by the number of occurrences in a descending order. If two or more words have the same count, they should be sorted according to their order in the original sentence. Assume that all letters are in english alphabet. You function should be case-insensitive, so for instance, the words “Perfect”
and “perfect”
should be considered the same word.
The engine should strip out punctuation (even in the middle of a word) and use whitespaces to separate words.
Analyze the time and space complexities of your solution. Try to optimize for time while keeping a polynomial space complexity.
Examples:
input: document = "Practice makes perfect. you'll only
get Perfect by practice. just practice!"
output: [ ["practice", "3"], ["perfect", "2"],
["makes", "1"], ["youll", "1"], ["only", "1"],
["get", "1"], ["by", "1"], ["just", "1"] ]
Important: please convert the occurrence integers in the output list to strings (e.g. "3" instead of 3). We ask this because in compiled languages such as C#, Java, C++, C etc., it’s not straightforward to create mixed-type arrays (as it is, for instance, in scripted languages like JavaScript, Python, Ruby etc.). The expected output will simply be an array of string arrays.
Constraints:
[time limit] 5000ms [input] string document [output] array.array.string
Language
To get a local copy up and running, follow these steps.
In order to run this project you need:
npm install
Nodejs
Clone this repository to your desired folder:
cd JavaScript-WordCountEngine-CodingChallenge
git clone https://github.com/JonahKayizzi/JavaScript-WordCountEngine-CodingChallenge.git
To run tests, run the following command:
npm run test
OR
Submit a pull_request and ensure that all auto_checks pass
👤 Jonathan Kayizzi
- GitHub: @JonahKayizzi
- Twitter: @JonahKayizzi
- LinkedIn: LinkedIn
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Contribute my providing more optimal approaches with better performance and time complexity
If you like this project you can give me a ⭐️
I would like to thank Pramp for this coding challenge