diff --git a/.eslintrc b/.eslintrc index ec0d68b9b851aecd5fed5b8c2c7b6c87f52f46f9..15eefba00ead3e95099b0064fe507a5cdc2e93e8 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 0e334b31d564a91255396fb7f88b4d69a59222fb..34564894180ba9f0cd3756db0ee6fcab573444c4 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 37c78d2c7091e17404f35b20fde47009186c4b00..f1798805179eff4ac35727965e88ae7912eacf8a 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 cc6a5c383acb3822e93c612998acf11958391231..1cf36988e32cdf145755066825bb4e43f5a0e10c 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 a50c31a3cef7f370724c9145687d80e016666795..c87c6a00796ba13787d9ee9f72070f0f8d1a80cf 100644 --- a/js/words.js +++ b/js/words.js @@ -1,6 +1,4 @@ -/* exported DICTIONARY */ - -const DICTIONARY = [ +export const DICTIONARY = [ "A", "AA", "AAA",