mirror of
https://github.com/trekhleb/javascript-algorithms.git
synced 2026-03-13 08:51:02 +08:00
Modify HashTable (#447)
Add a getValues() method to the HashTable data structure
This commit is contained in:
@@ -105,4 +105,16 @@ export default class HashTable {
|
||||
getKeys() {
|
||||
return Object.keys(this.keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of all the stored values in the hash table in the order of
|
||||
* the keys map.
|
||||
*
|
||||
* @return {*[]}
|
||||
*/
|
||||
getValues() {
|
||||
const keys = this.getKeys();
|
||||
|
||||
return keys.map(key => this.buckets[this.hash(key)].head.value.value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user