-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
30 lines (23 loc) · 1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const axios = require('axios');
const {getWordsObject, getTopTenWords, fetchApiData, createJSON} = require('./utils.js');
async function getFileData(){
let response = await axios.get("http://norvig.com/big.txt");
let content = response.data;
let topTenWordDetailsArray = [];
// get words object from whole response content
let wordsObj = getWordsObject(content);
// find top ten words
let topTen = getTopTenWords(wordsObj);
for(let iwrd=0; iwrd<topTen.length; iwrd++){
let word = topTen[iwrd];
// fetch api details like synonyms, pos for a word
let apiData = await fetchApiData(word);
// create json object for each word includin all required details
let getJson = createJSON(word, wordsObj[word], apiData.syn, apiData.pos);
//add details of top ten words to single array object
topTenWordDetailsArray.push(getJson);
}
console.log(topTenWordDetailsArray);
return topTenWordDetailsArray;
}
getFileData();