"# terriblytinytales-task"
To create a website which takes a number N from the user and after submitting the number, the user should be displayed with a list of N words that are most frequently occurring in the text file hosted on this website.
To run the website, there are no requirements as such because the website is hosted on Heroku cloud platform. Click here to redirect
- Languages: HTML5
- Frameworks
- CSS
- Bootstrap v4
- AJAX used to communicate with back-end
- Languages: Javascript
- Frameworks/NPM Modules
- Express.js @express@4.16.4
- request
- body-parser
- path
index.html -- (AJAX Call) --> index.js -> routes/ttt.route.js -> controllers/ttt.controller.js -> findOccurrences()
findOccurrences() -> controllers/ttt.controller.js -> routes/ttt.route.js -> index.js -> index.html -> AJAX Response
- Webpage having the following elements
- Header
- Footer
- Side Navigation Bar
- Consists of HTML Form
- Input Item: Inputs only value greater than 0
- Submit Button: When the form is submitted, processing begins and results is obtained below
- Result Table: After processing data, the result is diplayed in a tabular form
- Web API
- Homepage which displays landing webpage
- Contains GET type of API which takes the user input as the parameter and returns the result
- Algorithm
- Fetch the text file by creating a request to URL
- If successful,
- Check if total words are more than the user input
- Count frequency of each word and store into a HashMap
- The frequency is counted as
- Consider newline, tabspaces, vertical spaces, etc. as single whitespace
- Treat Common Punctuation as single whitespace
- Get rid of quotations (only at the start or end of the word)
- Different Cases with Same spelling should be considered as one word.
- Split the words into an array
- If word has a key
- Increment by one
- Else create the key with value 1.
- Sort the hashmap by their values in Decreasing order
- Slice the array to only N (desired input)
- Return the final result
- Else Return internal server error (500)
landing page:
Test input "3":
Test input "-9":
{
"info": {
"_postman_id": "9730eb30-2f6b-4221-a25f-b1d12b104449",
"name": "ttt-backend-test-collection-postman",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get N Occurrences",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://terriblytinytalestask.herokuapp.com/findOccurrences?userInput=4",
"protocol": "https",
"host": [
"terriblytinytalestask",
"herokuapp",
"com"
],
"path": [
"findOccurrences"
],
"query": [
{
"key": "userInput",
"value": "4"
}
]
},
"description": "GET Web API:\n1. Takes a number N as input\n2. Processes a text file hosted on https://terriblytinytales.com/test.txt\n3. Returns top N frequent occurences"
},
"response": []
},
{
"name": "Get N Occurrences 2",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://terriblytinytalestask.herokuapp.com/findOccurrences?userInput=10",
"protocol": "https",
"host": [
"terriblytinytalestask",
"herokuapp",
"com"
],
"path": [
"findOccurrences"
],
"query": [
{
"key": "userInput",
"value": "10"
}
]
},
"description": "GET Web API:\n1. Takes a number N as input\n2. Processes a text file hosted on https://terriblytinytales.com/test.txt\n3. Returns top N frequent occurences"
},
"response": []
},
{
"name": "Get N Occurrences 3",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://terriblytinytalestask.herokuapp.com/findOccurrences?userInput=50",
"protocol": "https",
"host": [
"terriblytinytalestask",
"herokuapp",
"com"
],
"path": [
"findOccurrences"
],
"query": [
{
"key": "userInput",
"value": "50"
}
]
},
"description": "GET Web API:\n1. Takes a number N as input\n2. Processes a text file hosted on https://terriblytinytales.com/test.txt\n3. Returns top N frequent occurences"
},
"response": []
},
{
"name": "Get N Occurrences 4 (negative)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://terriblytinytalestask.herokuapp.com/findOccurrences?userInput=-1",
"protocol": "https",
"host": [
"terriblytinytalestask",
"herokuapp",
"com"
],
"path": [
"findOccurrences"
],
"query": [
{
"key": "userInput",
"value": "-1"
}
]
},
"description": "GET Web API:\n1. Takes a number N as input\n2. Processes a text file hosted on https://terriblytinytales.com/test.txt\n3. Returns top N frequent occurences"
},
"response": []
},
{
"name": "Get N Occurrences 5 (negative)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://terriblytinytalestask.herokuapp.com/findOccurrences?userInput=-100",
"protocol": "https",
"host": [
"terriblytinytalestask",
"herokuapp",
"com"
],
"path": [
"findOccurrences"
],
"query": [
{
"key": "userInput",
"value": "-100"
}
]
},
"description": "GET Web API:\n1. Takes a number N as input\n2. Processes a text file hosted on https://terriblytinytales.com/test.txt\n3. Returns top N frequent occurences"
},
"response": []
},
{
"name": "Get N Occurrences 6 (negative)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://terriblytinytalestask.herokuapp.com/findOccurrences?userInput=-500000",
"protocol": "https",
"host": [
"terriblytinytalestask",
"herokuapp",
"com"
],
"path": [
"findOccurrences"
],
"query": [
{
"key": "userInput",
"value": "-500000"
}
]
},
"description": "GET Web API:\n1. Takes a number N as input\n2. Processes a text file hosted on https://terriblytinytales.com/test.txt\n3. Returns top N frequent occurences"
},
"response": []
},
{
"name": "Get N Occurrences 7 (negative)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://terriblytinytalestask.herokuapp.com/findOccurrences?userInput=999",
"protocol": "https",
"host": [
"terriblytinytalestask",
"herokuapp",
"com"
],
"path": [
"findOccurrences"
],
"query": [
{
"key": "userInput",
"value": "999"
}
]
},
"description": "GET Web API:\n1. Takes a number N as input\n2. Processes a text file hosted on https://terriblytinytales.com/test.txt\n3. Returns top N frequent occurences"
},
"response": []
},
{
"name": "Get N Occurrences 8 (negative)",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "https://terriblytinytalestask.herokuapp.com/findOccurrences?userInput=999",
"protocol": "https",
"host": [
"terriblytinytalestask",
"herokuapp",
"com"
],
"path": [
"findOccurrences"
],
"query": [
{
"key": "userInput",
"value": "999"
}
]
},
"description": "GET Web API:\n1. Takes a number N as input\n2. Processes a text file hosted on https://terriblytinytales.com/test.txt\n3. Returns top N frequent occurences"
},
"response": []
}
],
"protocolProfileBehavior": {}
}