chore: manual translations (#42811)
This commit is contained in:
committed by
GitHub
parent
a3395269a0
commit
c4fd49e5b7
@ -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--
|
||||
|
@ -12,11 +12,15 @@ In this challenge you will be creating a Priority Queue. A Priority Queue is a s
|
||||
|
||||
For instance, let’s imagine we have a priority queue with three items:
|
||||
|
||||
`[['kitten', 2], ['dog', 2], ['rabbit', 2]]`
|
||||
```js
|
||||
[['kitten', 2], ['dog', 2], ['rabbit', 2]]
|
||||
```
|
||||
|
||||
Here the second value (an integer) represents item priority. If we enqueue `['human', 1]` with a priority of `1` (assuming lower priorities are given precedence) it would then be the first item to be dequeued. The collection would look like this:
|
||||
|
||||
`[['human', 1], ['kitten', 2], ['dog', 2], ['rabbit', 2]]`.
|
||||
```js
|
||||
[['human', 1], ['kitten', 2], ['dog', 2], ['rabbit', 2]]
|
||||
```
|
||||
|
||||
We’ve started writing a `PriorityQueue` in the code editor. You will need to add an `enqueue` method for adding items with a priority, a `dequeue` method for removing and returning items, a `size` method to return the number of items in the queue, a `front` method to return the element at the front of the queue, and finally an `isEmpty` method that will return `true` if the queue is empty or `false` if it is not.
|
||||
|
||||
|
@ -77,8 +77,9 @@ The `peek` method should return the top element of the stack
|
||||
assert(
|
||||
(function () {
|
||||
var test = new Stack();
|
||||
test.push('CS61');
|
||||
test.push('CS50');
|
||||
return test.peek() === 'CS50';
|
||||
return test.peek() === 'CS50' && test.peek() === 'CS50';
|
||||
})()
|
||||
);
|
||||
```
|
||||
@ -89,8 +90,9 @@ The `pop` method should remove and return the top element of the stack
|
||||
assert(
|
||||
(function () {
|
||||
var test = new Stack();
|
||||
test.push('CS61');
|
||||
test.push('CS50');
|
||||
return test.pop() === 'CS50';
|
||||
return test.pop() === 'CS50' && test.pop() === 'CS61';
|
||||
})()
|
||||
);
|
||||
```
|
||||
@ -112,6 +114,7 @@ The `clear` method should remove all element from the stack
|
||||
assert(
|
||||
(function () {
|
||||
var test = new Stack();
|
||||
test.push('CS61');
|
||||
test.push('CS50');
|
||||
test.clear();
|
||||
return test.isEmpty();
|
||||
|
@ -31,7 +31,9 @@ assert(myMap.get('freeCodeCamp') === 'Awesome!');
|
||||
# --seed--
|
||||
|
||||
## --seed-contents--
|
||||
|
||||
```js
|
||||
|
||||
```
|
||||
|
||||
# --solutions--
|
||||
|
@ -12,15 +12,21 @@ Now that you have worked through ES5, you are going to perform something similar
|
||||
|
||||
To create a new empty set:
|
||||
|
||||
`var set = new Set();`
|
||||
```js
|
||||
var set = new Set();
|
||||
```
|
||||
|
||||
You can create a set with a value:
|
||||
|
||||
`var set = new Set(1);`
|
||||
```js
|
||||
var set = new Set(1);
|
||||
```
|
||||
|
||||
You can create a set with an array:
|
||||
|
||||
`var set = new Set([1, 2, 3]);`
|
||||
```js
|
||||
var set = new Set([1, 2, 3]);
|
||||
```
|
||||
|
||||
Once you have created a set, you can add the values you wish using the `add` method:
|
||||
|
||||
|
@ -14,13 +14,17 @@ While binary heaps may be implemented as tree structures with nodes that contain
|
||||
|
||||
For instance, consider this array representation of a binary min heap:
|
||||
|
||||
`[ 6, 22, 30, 37, 63, 48, 42, 76 ]`
|
||||
```js
|
||||
[ 6, 22, 30, 37, 63, 48, 42, 76 ]
|
||||
```
|
||||
|
||||
The root node is the first element, `6`. Its children are `22` and `30`. If we look at the relationship between the array indices of these values, for index `i` the children are `2 * i + 1` and `2 * i + 2`. Similarly, the element at index `0` is the parent of these two children at indices `1` and `2`. More generally, we can find the parent of a node at any index with the following: `Math.floor((i - 1) / 2)`. These patterns will hold true as the binary tree grows to any size. Finally, we can make a slight adjustment to make this arithmetic even easier by skipping the first element in the array. Doing this creates the following relationship for any element at a given index `i`:
|
||||
|
||||
Example array representation:
|
||||
|
||||
`[ null, 6, 22, 30, 37, 63, 48, 42, 76 ]`
|
||||
```js
|
||||
[ null, 6, 22, 30, 37, 63, 48, 42, 76 ]
|
||||
```
|
||||
|
||||
An element's left child: `i * 2`
|
||||
|
||||
|
@ -12,7 +12,9 @@ Let's practice removing items from an ES6 Set using the `delete` method.
|
||||
|
||||
First, create an ES6 Set:
|
||||
|
||||
`var set = new Set([1,2,3]);`
|
||||
```js
|
||||
var set = new Set([1,2,3]);
|
||||
```
|
||||
|
||||
Now remove an item from your Set with the `delete` method.
|
||||
|
||||
@ -46,8 +48,11 @@ assert(
|
||||
|
||||
```js
|
||||
function checkSet(){
|
||||
var set = null;
|
||||
return set;
|
||||
// Only change code below this line
|
||||
var set = null;
|
||||
|
||||
// Only change code above this line
|
||||
return set;
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -10,7 +10,9 @@ dashedName: typed-arrays
|
||||
|
||||
Arrays are JavaScript objects that can hold a lot of different elements.
|
||||
|
||||
`var complexArr = [1, 5, "2", "Word", {"name": "James"}];`
|
||||
```js
|
||||
var complexArr = [1, 5, "2", "Word", {"name": "James"}];
|
||||
```
|
||||
|
||||
Basically what happens in the background is that your browser will automatically give the right amount of memory space for that array. It will also change as needed if you add or remove data.
|
||||
|
||||
|
@ -12,15 +12,21 @@ Let's look at the .has and .size methods available on the ES6 Set object.
|
||||
|
||||
First, create an ES6 Set
|
||||
|
||||
`var set = new Set([1,2,3]);`
|
||||
```js
|
||||
var set = new Set([1,2,3]);
|
||||
```
|
||||
|
||||
The .has method will check if the value is contained within the set.
|
||||
|
||||
`var hasTwo = set.has(2);`
|
||||
```js
|
||||
var hasTwo = set.has(2);
|
||||
```
|
||||
|
||||
The .size method will return an integer representing the size of the Set
|
||||
|
||||
`var howBig = set.size;`
|
||||
```js
|
||||
var howBig = set.size;
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
Reference in New Issue
Block a user