{"action":"created","comment":{"url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/comments/67833322","id":67833322,"diff_hunk":"@@ -1,93 +1,100 @@\n-\"use strict\";\n-\n class Index {\n \n-\n-\n-    createIndex(filePath) {\n-        var self = this;\n-        this.indexObject = {};\n-        \n-        /* specifies the environment to be used */\n-        if (typeof window === 'object') {\n-\n-            return fetch(filePath).then(function(response) {\n-\n-                return response.json()\n-            })\n-            .then(function(data) {\n-                \n-                self.books = data;\n-                \n-                makeIndex()\n-\n-            });\n-            \n+  makeIndex(books) {\n+    /* this method creates the index and is to be called\n+    after the JSON file has been read */\n+    this.indexObject = {};\n+    books.forEach((book, docIndex) => {\n+      /* self.bookString is now a string without any special characters and trailing spaces */\n+      this.bookString = JSON.stringify(book).toLowerCase()\n+        .replace(/\\W/g, ' ')\n+        .replace(/\\s+/g, ' ')\n+        .trim();\n+\n+      /* self.stringArray is converted to a set to remove any duplication of words */\n+      this.stringArray = new Set((this.bookString.split(' ')));\n+\n+      this.stringArray.forEach(word => {\n+        if (!this.indexObject.hasOwnProperty(word)) {\n+          this.indexObject[word] = [docIndex];\n         } else {\n-            // import the file reader using require\n-            const fs = require('fs');\n-            \n-            self.books = JSON.parse(fs.readFileSync(filePath));\n-            \n-            makeIndex()\n-        }\n-\n-\n-        function makeIndex() {\n-        /* this method creates the index and is to be called after the JSON file has been read */\n-            \n-            self.books.forEach((book, docIndex) => {\n-\n-                self.bookString = JSON.stringify(book).toLowerCase().replace(/\\W/g, ' ').replace(/\\s+/g, ' ').trim();\n-            \n-            self.stringArray = self.bookString.split(' ');\n-            \n-            self.stringArray.forEach((word, wordIndex) => {\n-                    if (self.indexObject.hasOwnProperty(word)){\n-\n-                            self.indexObject[word].push(docIndex)\n-                        \n-                    }\n-                    else {\n-                        \n-                        self.indexObject[word] = [docIndex]\n-                    }\n-                    \n-                });\n-        \n-            });\n-    \n+          this.indexObject[word].push(docIndex);\n         }\n+      });\n+    });\n+  }\n+\n+  createIndex(filePath) {\n+    /* specifies the environment to be used */\n+    return new Promise((resolve, reject) => {\n+      if (typeof window === 'object') {\n+        return fetch(filePath)\n+        .then(response => response.json())\n+        .then(data => {\n+          this.books = data;\n+          this.makeIndex(data);\n+          return resolve();\n+        })\n+        .catch((error) => reject(error));\n+      }\n+      // import the  json file using require\n+\n+      try {\n+        const books = require(filePath); // eslint-disable-line global-require","path":"jasmine/src/invertedIndex.js","position":99,"original_position":99,"commit_id":"94e29bd35c6b0b13c40db24129522b7d3cf89abd","original_commit_id":"94e29bd35c6b0b13c40db24129522b7d3cf89abd","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"'const' is available in ES6 (use esnext option) or Mozilla JS extensions (use moz).","created_at":"2016-06-21T09:09:22Z","updated_at":"2016-06-21T09:09:22Z","html_url":"https://github.com/andela-tbaraza/Inverted-Index/pull/1#discussion_r67833322","pull_request_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/comments/67833322"},"html":{"href":"https://github.com/andela-tbaraza/Inverted-Index/pull/1#discussion_r67833322"},"pull_request":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/1","id":74495870,"html_url":"https://github.com/andela-tbaraza/Inverted-Index/pull/1","diff_url":"https://github.com/andela-tbaraza/Inverted-Index/pull/1.diff","patch_url":"https://github.com/andela-tbaraza/Inverted-Index/pull/1.patch","issue_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues/1","number":1,"state":"open","locked":false,"title":"Dev","user":{"login":"andela-tbaraza","id":19430106,"avatar_url":"https://avatars.githubusercontent.com/u/19430106?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-tbaraza","html_url":"https://github.com/andela-tbaraza","followers_url":"https://api.github.com/users/andela-tbaraza/followers","following_url":"https://api.github.com/users/andela-tbaraza/following{/other_user}","gists_url":"https://api.github.com/users/andela-tbaraza/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-tbaraza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-tbaraza/subscriptions","organizations_url":"https://api.github.com/users/andela-tbaraza/orgs","repos_url":"https://api.github.com/users/andela-tbaraza/repos","events_url":"https://api.github.com/users/andela-tbaraza/events{/privacy}","received_events_url":"https://api.github.com/users/andela-tbaraza/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-20T19:07:33Z","updated_at":"2016-06-21T09:09:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4211851e65161ef0f6262c796051ebacbd328907","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/1/commits","review_comments_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/1/comments","review_comment_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues/1/comments","statuses_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/statuses/94e29bd35c6b0b13c40db24129522b7d3cf89abd","head":{"label":"andela-tbaraza:dev","ref":"dev","sha":"94e29bd35c6b0b13c40db24129522b7d3cf89abd","user":{"login":"andela-tbaraza","id":19430106,"avatar_url":"https://avatars.githubusercontent.com/u/19430106?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-tbaraza","html_url":"https://github.com/andela-tbaraza","followers_url":"https://api.github.com/users/andela-tbaraza/followers","following_url":"https://api.github.com/users/andela-tbaraza/following{/other_user}","gists_url":"https://api.github.com/users/andela-tbaraza/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-tbaraza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-tbaraza/subscriptions","organizations_url":"https://api.github.com/users/andela-tbaraza/orgs","repos_url":"https://api.github.com/users/andela-tbaraza/repos","events_url":"https://api.github.com/users/andela-tbaraza/events{/privacy}","received_events_url":"https://api.github.com/users/andela-tbaraza/received_events","type":"User","site_admin":false},"repo":{"id":59958362,"name":"Inverted-Index","full_name":"andela-tbaraza/Inverted-Index","owner":{"login":"andela-tbaraza","id":19430106,"avatar_url":"https://avatars.githubusercontent.com/u/19430106?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-tbaraza","html_url":"https://github.com/andela-tbaraza","followers_url":"https://api.github.com/users/andela-tbaraza/followers","following_url":"https://api.github.com/users/andela-tbaraza/following{/other_user}","gists_url":"https://api.github.com/users/andela-tbaraza/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-tbaraza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-tbaraza/subscriptions","organizations_url":"https://api.github.com/users/andela-tbaraza/orgs","repos_url":"https://api.github.com/users/andela-tbaraza/repos","events_url":"https://api.github.com/users/andela-tbaraza/events{/privacy}","received_events_url":"https://api.github.com/users/andela-tbaraza/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andela-tbaraza/Inverted-Index","description":"","fork":false,"url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index","forks_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/forks","keys_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/teams","hooks_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/hooks","issue_events_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues/events{/number}","events_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/events","assignees_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/assignees{/user}","branches_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/branches{/branch}","tags_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/tags","blobs_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/statuses/{sha}","languages_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/languages","stargazers_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/stargazers","contributors_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/contributors","subscribers_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/subscribers","subscription_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/subscription","commits_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/contents/{+path}","compare_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/merges","archive_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/downloads","issues_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues{/number}","pulls_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls{/number}","milestones_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/milestones{/number}","notifications_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/labels{/name}","releases_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/releases{/id}","deployments_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/deployments","created_at":"2016-05-29T18:40:52Z","updated_at":"2016-06-02T19:45:00Z","pushed_at":"2016-06-21T09:09:12Z","git_url":"git://github.com/andela-tbaraza/Inverted-Index.git","ssh_url":"git@github.com:andela-tbaraza/Inverted-Index.git","clone_url":"https://github.com/andela-tbaraza/Inverted-Index.git","svn_url":"https://github.com/andela-tbaraza/Inverted-Index","homepage":null,"size":3007,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"andela-tbaraza:master","ref":"master","sha":"471404f5b4d582db20472bbc0387b66d63b5430f","user":{"login":"andela-tbaraza","id":19430106,"avatar_url":"https://avatars.githubusercontent.com/u/19430106?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-tbaraza","html_url":"https://github.com/andela-tbaraza","followers_url":"https://api.github.com/users/andela-tbaraza/followers","following_url":"https://api.github.com/users/andela-tbaraza/following{/other_user}","gists_url":"https://api.github.com/users/andela-tbaraza/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-tbaraza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-tbaraza/subscriptions","organizations_url":"https://api.github.com/users/andela-tbaraza/orgs","repos_url":"https://api.github.com/users/andela-tbaraza/repos","events_url":"https://api.github.com/users/andela-tbaraza/events{/privacy}","received_events_url":"https://api.github.com/users/andela-tbaraza/received_events","type":"User","site_admin":false},"repo":{"id":59958362,"name":"Inverted-Index","full_name":"andela-tbaraza/Inverted-Index","owner":{"login":"andela-tbaraza","id":19430106,"avatar_url":"https://avatars.githubusercontent.com/u/19430106?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-tbaraza","html_url":"https://github.com/andela-tbaraza","followers_url":"https://api.github.com/users/andela-tbaraza/followers","following_url":"https://api.github.com/users/andela-tbaraza/following{/other_user}","gists_url":"https://api.github.com/users/andela-tbaraza/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-tbaraza/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-tbaraza/subscriptions","organizations_url":"https://api.github.com/users/andela-tbaraza/orgs","repos_url":"https://api.github.com/users/andela-tbaraza/repos","events_url":"https://api.github.com/users/andela-tbaraza/events{/privacy}","received_events_url":"https://api.github.com/users/andela-tbaraza/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andela-tbaraza/Inverted-Index","description":"","fork":false,"url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index","forks_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/forks","keys_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/teams","hooks_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/hooks","issue_events_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues/events{/number}","events_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/events","assignees_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/assignees{/user}","branches_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/branches{/branch}","tags_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/tags","blobs_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/statuses/{sha}","languages_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/languages","stargazers_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/stargazers","contributors_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/contributors","subscribers_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/subscribers","subscription_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/subscription","commits_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/contents/{+path}","compare_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/merges","archive_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/downloads","issues_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues{/number}","pulls_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls{/number}","milestones_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/milestones{/number}","notifications_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/labels{/name}","releases_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/releases{/id}","deployments_url":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/deployments","created_at":"2016-05-29T18:40:52Z","updated_at":"2016-06-02T19:45:00Z","pushed_at":"2016-06-21T09:09:12Z","git_url":"git://github.com/andela-tbaraza/Inverted-Index.git","ssh_url":"git@github.com:andela-tbaraza/Inverted-Index.git","clone_url":"https://github.com/andela-tbaraza/Inverted-Index.git","svn_url":"https://github.com/andela-tbaraza/Inverted-Index","homepage":null,"size":3007,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/1"},"html":{"href":"https://github.com/andela-tbaraza/Inverted-Index/pull/1"},"issue":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues/1"},"comments":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/andela-tbaraza/Inverted-Index/statuses/94e29bd35c6b0b13c40db24129522b7d3cf89abd"}}}}
{"actor":{"display_login":"houndci-bot"}}