chore: manual translations (#42811)

This commit is contained in:
Nicholas Carrigan (he/him)
2021-07-09 21:23:54 -07:00
committed by GitHub
parent a3395269a0
commit c4fd49e5b7
806 changed files with 8935 additions and 4378 deletions

View File

@ -20,6 +20,8 @@ Let's create the basic functionality of a hash table. We've created a naive hash
Be sure to write your code to account for collisions!
**Note:** The `remove` method tests won't pass until the `add` and `lookup` methods are correctly implemented.
# --hints--
The HashTable data structure should exist.
@ -50,20 +52,6 @@ assert(
);
```
The HashTable should have a remove method.
```js
assert(
(function () {
var test = false;
if (typeof HashTable !== 'undefined') {
test = new HashTable();
}
return typeof test.remove === 'function';
})()
);
```
The HashTable should have a lookup method.
```js
@ -78,6 +66,20 @@ assert(
);
```
The HashTable should have a remove method.
```js
assert(
(function () {
var test = false;
if (typeof HashTable !== 'undefined') {
test = new HashTable();
}
return typeof test.remove === 'function';
})()
);
```
The add method should add key value pairs and the lookup method should return the values associated with a given key.
```js
@ -103,14 +105,40 @@ assert(
if (typeof HashTable !== 'undefined') {
test = new HashTable();
}
test.add = addMethodSolution;
test.add('key', 'value');
test.remove('key');
return !test.collection.hasOwnProperty(hashValue);
})()
);
```
The remove method should only remove the correct key value pair.
```js
assert(
(function () {
var test = false;
var hashValue = hash('key');
if (typeof HashTable !== 'undefined') {
test = new HashTable();
}
test.add('key', 'value');
test.add('yek', 'value');
test.add('altKey', 'value');
test.remove('yek');
if (test.lookup('yek') || !test.lookup('key') || !test.lookup('altKey')) {
return false;
}
test.remove('key');
return !test.collection.hasOwnProperty(hashValue) && test.lookup('altKey');
})()
);
```
Items should be added using the hash function.
```js
@ -165,14 +193,6 @@ var hash = string => {
}
return hash;
};
var addMethodSolution = function(key, val) {
var theHash = hash(key);
if (!this.collection.hasOwnProperty(theHash)) {
this.collection[theHash] = {};
}
this.collection[theHash][key] = val;
}
```
## --seed-contents--