PacktPublishing / Learning-JavaScript-Data-Structures-and-Algorithms-Third-Edition

Learning JavaScript Data Structures and Algorithms (Third Edition), published by Packt
MIT License
1.05k stars 428 forks source link

fix: fix hash-table-linear-probing file get method #12

Closed hefeng6500 closed 3 years ago

hefeng6500 commented 3 years ago

Hello!

test demo

const hash = new HashTableLinearProbing();
hash.put('Ygritte', 'ygritte@email.com'); // hashCode: 4
hash.put('Jonathan', 'jonathan@email.com'); // hashCode: 5
hash.put('Jamie', 'jamie@email.com'); // hashCode: 5

console.log(hash.get('Jamie')); // jonathan@email.com

this log should be 'jamie@email.com', but get 'jonathan@email.com'

The Error log reason is this line return this.table[position].value after while loop

not return this.table[position].value,

the correct is return this.table[index].value