Add getValues() method to HashTable and update LinkedList READMEs.

This commit is contained in:
Oleksii Trekhleb
2020-12-11 09:14:48 +01:00
parent 46daaf51c5
commit 1b0e27ab86
4 changed files with 28 additions and 8 deletions

View File

@@ -107,14 +107,15 @@ export default class HashTable {
}
/**
* Gets the list of all the stored values in the hash table in the order of
* the keys map.
* Gets the list of all the stored values in the hash table.
*
* @return {*[]}
*/
getValues() {
const keys = this.getKeys();
return keys.map(key => this.buckets[this.hash(key)].head.value.value);
return this.buckets.reduce((values, bucket) => {
const bucketValues = bucket.toArray()
.map((linkedListNode) => linkedListNode.value.value);
return values.concat(bucketValues);
}, []);
}
}