/**
 * inverted index class
 * @class
 */
class InvertedIndex {
  /**
   * class constructor
   * @constructor
   */
  constructor() {
    this.indexes = {};
  }

  /**
   * Check if a json file is valid
   * @function isValidJson
   * @param {Object} jsonArray Array of json objects
   * @return {Boolean} True or false if json file is valid
   */
  isValidJson(jsonArray) {
    if (typeof jsonArray !== 'object' || jsonArray.length === 0) {
      return false;
    }
    try {
      jsonArray.forEach((item) => {
        if (!(item.hasOwnProperty('title') && item.hasOwnProperty('text'))) {
          return false;
        }
      });
      return true;
    } catch (err) {
      return false;
    }
  }

  /**
   * getToken
   * @param {String} text Strings of texts
   * @return {Array} An array of splitted texts
   */
  getToken(text) {
    const invalid = /[^\w\s]/g;
    return text.replace(invalid, ' ').toLowerCase()
      .split(' ')
      .filter(item => Boolean(item));
  }

    /**
     * createIndex
     * @param {String} fileContent Name of the uploaded file.
     * @param {Array} fileName Uploaded json file content
     * @return {null} no return value
     */
  createIndex(fileContent, fileName) {
    if (this.isValidJson(fileContent)) {
      if (!(this.indexes[fileName])) {
        this.indexes[fileName] = {};
        fileContent.forEach((doc, docIndex) => {
          const newString = `${doc.title} ${doc.text}`;
          const tokenArray = this.getToken(newString);
          tokenArray.forEach((token) => {
            if (this.indexes[fileName][token] === undefined) {
              this.indexes[fileName][token] = [];
              this.indexes[fileName][token].push(docIndex);
            } else if (this.indexes[fileName][token] &&
                this.indexes[fileName][token].indexOf(docIndex) === -1) {
              this.indexes[fileName][token].push(docIndex);
            }
          });
        });
      }
    }
  }


    /**
     * getIndex
     * @return {Object} An object of each word and their indexex
     */
  getIndex() {
    return this.indexes;
  }

    /**
     * searchIndex
     * @param {String} word Word to be searched in the index
     * @param {String} fileName The filename to search for words
     * @return {Object} Words and their indexes
     */
  searchIndex(word, fileName = null) {
    const result = {};
    const cleanWord = this.getToken(word);
    cleanWord.forEach((text) => {
      if (this.indexes[fileName].hasOwnProperty(text)) {
        result[text] = this.indexes[fileName][text];
      }
    });
    return result;
  }

}

@@ -1019,30 +1019,28 @@
   * @param %7B
-String
+JSON
 %7D fileConten
@@ -1045,66 +1045,8 @@
 ent 
-Name of the uploaded file.%0A     * @param %7BArray%7D fileName 
 Uplo
@@ -1088,29 +1088,46 @@
 rn %7B
-null%7D no return value
+Object%7D words in file with thier index
 %0A   
@@ -1156,26 +1156,16 @@
 eContent
-, fileName
 ) %7B%0A    
@@ -1205,86 +1205,8 @@
 ) %7B%0A
-      if (!(this.indexes%5BfileName%5D)) %7B%0A        this.indexes%5BfileName%5D = %7B%7D;%0A  
     
@@ -1244,26 +1244,24 @@
 Index) =%3E %7B%0A
-  
         cons
@@ -1306,26 +1306,24 @@
 %7D%60;%0A        
- 
- 
 const tokenA
@@ -1363,18 +1363,16 @@
         
-  
 tokenArr
@@ -1409,57 +1409,33 @@
     
-  if (this.indexes%5BfileName%5D%5Btoken%5D === undefined
+if (token in this.indexes
 ) %7B%0A
@@ -1438,34 +1438,36 @@
 ) %7B%0A            
-  
+if (
 this.indexes%5Bfil
@@ -1467,30 +1467,42 @@
 xes%5B
-fileName%5D%5Btoken%5D = %5B%5D;
+token%5D.indexOf(docIndex) === -1) %7B
 %0A   
@@ -1521,34 +1521,24 @@
 his.indexes%5B
-fileName%5D%5B
 token%5D.push(
@@ -1565,122 +1565,25 @@
    %7D
- else if (this.indexes%5BfileName%5D%5Btoken%5D &&%0A                this.indexes%5BfileName%5D%5Btoken%5D.indexOf(docIndex) === -1)
+%0A          %7D else
  %7B%0A 
@@ -1585,34 +1585,32 @@
 e %7B%0A            
-  
 this.indexes%5Bfil
@@ -1610,38 +1610,26 @@
 xes%5B
-fileName%5D%5Btoken%5D.push(
+token%5D = %5B
 docIndex
 );%0A 
@@ -1616,33 +1616,33 @@
 ken%5D = %5BdocIndex
-)
+%5D
 ;%0A            %7D%0A
@@ -1641,25 +1641,9 @@
     
-  %7D%0A          %7D);
+%7D
 %0A   
@@ -1654,24 +1654,26 @@
  %7D);%0A      %7D
+);
 %0A    %7D%0A  %7D%0A%0A
@@ -1672,17 +1672,16 @@
  %7D%0A  %7D%0A%0A
-%0A
     /**%0A
@@ -1914,112 +1914,34 @@
  * @
-param %7BString%7D fileName The filename to search for words%0A     * @return %7BObject%7D Words and their indexes
+return %7BArray%7D description
 %0A   
@@ -1967,25 +1967,8 @@
 word
-, fileName = null
 ) %7B%0A
@@ -2089,26 +2089,16 @@
 .indexes
-%5BfileName%5D
 .hasOwnP
@@ -2110,16 +2110,26 @@
 ty(text)
+%0A         
 ) %7B%0A    
@@ -2164,18 +2164,8 @@
 xes%5B
-fileName%5D%5B
 text

Revert "modify inverted index class"