 let Index = (function () {
    const container = {};
    this.fileCheck=(fileContents) => {
    if (fileContents.files === undefined) {
        return message = {
            type: "Empty",
            status: false,
            message: fileContents.name + "is empty!"
        };
    }
    if (typeof fileContents === "object") {
        return message = {
            type: "Valid",
            status: true,
            message: fileContents.name + " has been indexed successfully."
        };
    }
    let x = stringify(fileContents);
    if ((JSON.parse(x)) === false) {
                return message = {
                    type: "invalidFormat",
                    status: false,
                    message: fileContents.name + "Invalid format."
                }
            }
}; 
 // method that sanitizes  input
 this.sanitizeInput = (content)=> {
    let characters = content.trim().replace(/[.[,\]/#!$%\^&\*;:@{}=\-_`~()]/g, '').toLowerCase().split(' ');
    return characters;
  };
  // method that check as to whether word has been indexed
    this.checkIndex = (words , file , source , id ) => {
        words.forEach( (word) => {
            let newWord = this.sanitizeInput(word);
            // check if newWord has been indexed before
            if (container[file][newWord] === undefined) {    
                container[file][newWord] = {};   
                container[file][newWord][id] = {
                    source: source,
                    file:file
                };
            } 
            container[file][newWord][id] = {
                source: source,
                file: file
            };
        });
    }
// method that creates indices
    this.createIndex = (fileContents)=> {
        let check = this.fileCheck(fileContents);
        if(check.type === "Empty")
        {  
          alert('It looks like you uploaded an empty JSON file.');
        }
        else if(check.type === "invalidFormat")
        {
         alert('It looks like the file is in bad format.');
        }
        else if (check.type === "Valid") {
                let docs = fileContents.files;
                let arr = [];
                container[fileContents.name] = {
                  uploadedFile: ( () => {
                        for (let i = 0; i < docs.length; i++) {
                            arr.push(i);
                        }
                        return arr;
                    })()    
                }
                for (let i = 0; i < docs.length; i++) {
                    let f = docs[i];
                    // split title into an array
                    let splittedTitle = f.title.split(" ");
                    this.checkIndex(splittedTitle, fileContents.name, f, i);
                    // split the text into an array then index it.
                    let splittedText = f.text.split(" ");
                    this.checkIndex(splittedText, fileContents.name, f, i); 
                }     
                return check;
        }      
    }
// method that return index
     this.getIndex = (fName) => {
        if (fName && typeof fName === "string") {
            return container[fName];
        } else {
            return container;
        }
    }  
// search methods
    this.search = (termsArray ,fName) => {
        const searchResults = {};
        termsArray.forEach((i ,j) =>{
            console.log(fName);
            if (fName.hasOwnProperty(i)){
                searchResults[termsArray[j]] = fName[i];
            }
            else {
                searchResults[termsArray[j]] = [];
            }
        });
        return searchResults;
    }
    this.searchIndex = (currFile , ...searchTerm) => {
        const searchResults = {};
        let termsArray = [];
        if (typeof(searchTerm) === 'string'){
            termsArray = this.sanitizeInput(searchTerm);
        }
        else{
            termsArray = searchTerm;
        }
        if (!currFile) {
            for (let i in container) {
                searchResults[i] = this.search(termsArray , container[i]);
            }
        }
        else{ 
            try{   
            let file =  container[currFile];
            searchResults[file] = this.search(termsArray , file);
        }
        catch(e){  
               return null;      
            }
        }
        return searchResults;
    }    
});

@@ -176,16 +176,20 @@
  type: %22
+file
 Empty%22,%0A
@@ -375,16 +375,20 @@
  type: %22
+file
 Valid%22,%0A
@@ -1808,16 +1808,20 @@
 pe === %22
+file
 Empty%22)%0A
@@ -2070,16 +2070,20 @@
 pe === %22
+file
 Valid%22) 
@@ -2104,19 +2104,23 @@
     let 
-doc
+indFile
 s = file
@@ -2161,24 +2161,71 @@
 t arr = %5B%5D;%0A
+                console.log(fileContents.name)%0A
             
@@ -2339,35 +2339,39 @@
 (let i = 0; i %3C 
-doc
+indFile
 s.length; i++) %7B
@@ -2557,19 +2557,23 @@
  0; i %3C 
-doc
+indFile
 s.length
@@ -2613,11 +2613,15 @@
 f = 
-doc
+indFile
 s%5Bi%5D
@@ -3332,16 +3332,24 @@
 s.search
+Feedback
  = (term
@@ -3599,24 +3599,28 @@
       else %7B
+    
 %0A           
@@ -3625,44 +3625,57 @@
     
-   searchResults%5BtermsArray%5Bj%5D%5D = %5B%5D
+alert('Sorry , but nothing matched your search.')
 ;%0A  
@@ -4128,32 +4128,40 @@
 i%5D = this.search
+Feedback
 (termsArray , co
@@ -4322,16 +4322,24 @@
 s.search
+Feedback
 (termsAr

fix issues