From f6e881d26c720ae285de5929e3e6324ac2e2b60a Mon Sep 17 00:00:00 2001 From: Brady James Garvin <bgarvin@cse.unl.edu> Date: Mon, 2 Dec 2019 12:05:01 -0600 Subject: [PATCH] Updated lab for 2019. --- .eslintrc | 3 +++ index.html | 6 ++---- js/hash_table.js | 4 +--- js/index.js | 3 ++- js/words.js | 4 +--- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.eslintrc b/.eslintrc index ec0d68b..15eefba 100755 --- a/.eslintrc +++ b/.eslintrc @@ -4,6 +4,9 @@ "browser": true, "jquery": true, }, + "parserOptions": { + "sourceType": "module", + }, "rules": { "no-await-in-loop": "warn", "no-compare-neg-zero": "warn", diff --git a/index.html b/index.html index 0e334b3..3456489 100644 --- a/index.html +++ b/index.html @@ -6,15 +6,13 @@ <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Hashing</title> <link rel="stylesheet" type="text/css" href="css/index.css"> + <script defer="true" src="libraries/jquery/jquery.min.js"></script> + <script defer="true" type="module" src="js/index.js"></script> </head> <body> <div id="time"></div> <div id="freeness"></div> - <script src="libraries/jquery/jquery.min.js"></script> - <script src="js/hash_table.js"></script> - <script src="js/words.js"></script> - <script src="js/index.js"></script> </body> </html> diff --git a/js/hash_table.js b/js/hash_table.js index 37c78d2..f179880 100644 --- a/js/hash_table.js +++ b/js/hash_table.js @@ -1,5 +1,3 @@ -/* exported HashTable */ - function mod(value, modulus) { const result = value % modulus; return result < 0 ? result + modulus : result; @@ -38,7 +36,7 @@ function createBuckets(count) { const INITIAL_HASH_TABLE_CAPACITY = 7; // eslint-disable-line no-magic-numbers const MAXIMUM_LOAD_FACTOR = 2 / 3; // eslint-disable-line no-magic-numbers -class HashTable { +export class HashTable { constructor(hashFunction) { this._hashFunction = (element) => mod(hashFunction(element), this._buckets.length); this._buckets = createBuckets(increaseToPseudoPrime(INITIAL_HASH_TABLE_CAPACITY)); diff --git a/js/index.js b/js/index.js index cc6a5c3..1cf3698 100644 --- a/js/index.js +++ b/js/index.js @@ -1,4 +1,5 @@ -/* globals HashTable DICTIONARY */ +import {HashTable} from './hash_table.js'; +import {DICTIONARY} from './words.js'; /* eslint-disable no-magic-numbers */ diff --git a/js/words.js b/js/words.js index a50c31a..c87c6a0 100644 --- a/js/words.js +++ b/js/words.js @@ -1,6 +1,4 @@ -/* exported DICTIONARY */ - -const DICTIONARY = [ +export const DICTIONARY = [ "A", "AA", "AAA", -- GitLab