app/js/invertedIndex.js
/**
   * Creates an index object from the file content and stores it
   * @function
   * @param {String} fileName name of uploaded file
   * @param {Array} books content of uploaded file
   * @return {Object} index of the uploaded file
   */
Creates an index object from the file content and stores it
@function
@param {String} fileName name of uploaded file
@param {Array} books content of uploaded file
@return {Object} index of the uploaded file
Creates an index object from the file content and stores it @function @param { String } fileName name of uploaded file @param { Array } books content of uploaded file @return { Object } index of the uploaded file
createIndex(fileName, books) {
    const indices = {};
    books.forEach((book, index) => {
      let tokens = `${book.title} ${book.text}`;
      tokens = InvertedIndex.tokenize(tokens);
      tokens.forEach((word) => {
        if (indices[word]) {
          if (indices[word].indexOf(index) === -1) {
            indices[word].push(index);
          }
        } else {
          indices[word] = [index];
        }
      });
    });
    this.filenames.push(fileName);
    this.indexed[fileName] = {
      eachWord: indices,
      count: books.length
    };
  }
createIndex ( fileName , books ) { const indices = { } ; books . forEach ( ( book , index ) => { let tokens = ` ${ book . title } ${ book . text } ` ; tokens = InvertedIndex . tokenize ( tokens ) ; tokens . forEach ( ( word ) => { if ( indices [ word ] ) { if ( indices [ word ] . indexOf ( index ) === - 1 ) { indices [ word ] . push ( index ) ; } } else { indices [ word ] = [ index ] ; } } ) ; } ) ; this . filenames . push ( fileName ) ; this . indexed [ fileName ] = { eachWord : indices , count : books . length } ; }
Creates an index object from the file content and stores it
 @function
 @param {String} fileName name of uploaded file
 @param {Array} books content of uploaded file
 @return {Object} index of the uploaded file
Creates an index object from the file content and stores it @function @param { String } fileName name of uploaded file @param { Array } books content of uploaded file @return { Object } index of the uploaded file