// get the json file contents
var getBooks = function() {
  var booksJson;
  $.ajax({
    async: false,
    url: 'books.json',
    dataType: 'json',
    success: function(response) {
      booksJson = response;
    }
  });
  return booksJson;
};
var books = getBooks();

var Index = function(){
  this.books = books;
};

Index.prototype.createIndex = function() {
  var indexObj = {},
  filePath = this.books;
  for ( var i = 0; i < filePath.length; i++ ) {
    for ( var j in filePath[i] ) {

      // tokenisation of json file contents
      var arrToken = filePath[i][j].split(' ');
      for ( var k = 0; k < arrToken.length; k++ ) {
        var strToken = arrToken[k].toLowerCase().replace(/[:,.]/g, '');

        // building the index from the tokenized words
        if ( indexObj.hasOwnProperty(strToken) ) {
          var objKey = indexObj[strToken];
          if ( parseInt(i) ) {
            var arrObj = parseInt(i);
            if ( objKey.indexOf(arrObj) < 0 ) {
              objKey.push(arrObj);
              indexObj[strToken] = objKey;
            }
          }
        } 
        else {
          indexObj[strToken] = [parseInt(i)];
        }
      }
    }
  }
  return indexObj;
};

var indexChild = new Index();
var getIndex = indexChild.createIndex();

Index.prototype.searchIndex = function(terms) {
  var searchArr = [];

  // looping through the arguments to allow for multiple words search
  for ( var i = 0; i < terms.length; i++ ) {
    if ( getIndex.hasOwnProperty(terms[i]) ) {
      searchArr.push(getIndex[terms[i]]);
    } 
    else {
      searchArr.push('Word Not Found!');
    }
  }
  return searchArr;
};

@@ -1,14 +1,77 @@
 // 
-get
+index constructor%0Avar Index = function()%7B%7D;%0A%0A// method to retrieve
  the jso
@@ -86,20 +86,32 @@
 ontents%0A
-var 
+Index.prototype.
 getBooks
@@ -114,32 +114,40 @@
 ooks = function(
+filePath
 ) %7B%0A  var booksJ
@@ -193,20 +193,16 @@
 rl: 
-'books.json'
+filePath
 ,%0A  
@@ -322,82 +322,66 @@
 %0A%7D;%0A
-var books = getBooks();%0A%0Avar Index = function()%7B%0A  this.books = books;%0A%7D;%0A
+%0A// method to create the index from the json file contents
 %0AInd
@@ -416,16 +416,24 @@
 unction(
+filePath
 ) %7B%0A  va
@@ -455,29 +455,42 @@
 ,%0A  
-filePath = this.books
+booksArr = this.getBooks(filePath)
 ;%0A  
@@ -510,24 +510,24 @@
  0; i %3C 
-filePath
+booksArr
 .length;
@@ -554,24 +554,24 @@
 ar j in 
-filePath
+booksArr
 %5Bi%5D ) %7B%0A
@@ -636,24 +636,24 @@
 Token = 
-filePath
+booksArr
 %5Bi%5D%5Bj%5D.s
@@ -778,11 +778,13 @@
 e(/%5B
-:,.
+%5E%5Cw%5Cs
 %5D/g,
@@ -1287,79 +1287,58 @@
 %7D;%0A%0A
-var indexChild = new Index();%0Avar getIndex = indexChild.createIndex();%0A
+// method to search the index for specific word(s)
 %0AInd
@@ -1697,12 +1697,121 @@
 archArr;%0A%7D;%0A
+%0A// new instance of Index%0Avar indexChild = new Index();%0Avar getIndex = indexChild.createIndex('books.json');%0A

refactor index prototypes