I need to implement a hash table and hash function using JavaScript.
The goal is to implement a FLASHCARD program for learning French.
For now, for each item I want to store 1)English word, 2)French word 3)a phrase example in French 4) the translation from French to English.
Possibly in the future it will also be necessary to consider images and other things.
For now my idea for hash table is the following:
var words = [['être', 'to be', 'Je suis professeur d’anglais', 'I am a English Teacher'], [, , , ], ...];
I was thinking a function like this.
var flashcards = (function () {
var words = [['être','to be','Je suis professeur d’anglais','I am a English Teacher'],[,,,]];
return function (n) {
return words[n];
};
}());
alert(flashcards(0)); // 'être, ....'
Please give me your suggestions regarding this code
and, above all, a efficient way to find elements in hash table.
First of all, that has nothing to do with a hash table. It’s just a 2d array 🙂 No hashing there, and you don’t need any either.
I think you’d be better off making an object for the flash card so you can access properties by name. Then just make an array of that object:
That should get you started: JSFiddle