Hello
I am looking for an efficient way to write the followng pseudo-code:
1) I start with an empty hashtable
2) I iterate over an array holding various integers (for example: 2, 100, 5555, 234)
3) For each integer, I need to check if it is already in the hashtable
4) If not, then I need to add it to the hashtable
5) If yes, I need to add it to a second array that will hold all the repeating integers
My questions are:
– How can I define a hashtable in JavaScript? Can I use arrays? I want them to be as efficient as hashtable in terms of element lookup. Step 3 will take O(N) in an array but O(1) in hashtable
– Do the keys have to be strings, or can I use integers and still enjoy a hashtable
– How can I tell if an element is already in the hashtable (array) ?
regards