fix(curriculum) replace single-line blocks with multi-line blocks for… (#41526)
* fix(curriculum) replace single-line blocks with multi-line blocks for issue 51418 Data visualization and Coding Interview Prep portions. * Update execute-a-markov-algorithm.md Implemented as inline code blocks as discussed * Adding missed blocks * Last file added
This commit is contained in:
@ -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.
|
||||
|
||||
|
@ -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--
|
||||
|
||||
|
@ -40,13 +40,7 @@ the shop -> my brother
|
||||
a never used -> .terminating rule
|
||||
</pre>
|
||||
|
||||
Sample text of:
|
||||
|
||||
`I bought a B of As from T S.`
|
||||
|
||||
Should generate the output:
|
||||
|
||||
`I bought a bag of apples from my brother.`
|
||||
Sample text of `I bought a B of As from T S.` should generate the output `I bought a bag of apples from my brother.`
|
||||
|
||||
**Ruleset 2:**
|
||||
|
||||
@ -61,13 +55,7 @@ the shop -> my brother
|
||||
a never used -> .terminating rule
|
||||
</pre>
|
||||
|
||||
Sample text of:
|
||||
|
||||
`I bought a B of As from T S.`
|
||||
|
||||
Should generate:
|
||||
|
||||
`I bought a bag of apples from T shop.`
|
||||
Sample text of `I bought a B of As from T S.` should generate `I bought a bag of apples from T shop.`
|
||||
|
||||
**Ruleset 3:**
|
||||
|
||||
@ -86,13 +74,7 @@ the shop -> my brother
|
||||
a never used -> .terminating rule
|
||||
</pre>
|
||||
|
||||
Sample text of:
|
||||
|
||||
`I bought a B of As W my Bgage from T S.`
|
||||
|
||||
Should generate:
|
||||
|
||||
`I bought a bag of apples with my money from T shop.`
|
||||
Sample text of `I bought a B of As W my Bgage from T S.` should generate `I bought a bag of apples with my money from T shop.`
|
||||
|
||||
**Ruleset 4:**
|
||||
|
||||
@ -128,13 +110,7 @@ _1 -> 1
|
||||
_+_ ->
|
||||
</pre>
|
||||
|
||||
Sample text of:
|
||||
|
||||
`_1111*11111_`
|
||||
|
||||
should generate the output:
|
||||
|
||||
`11111111111111111111`
|
||||
Sample text of `_1111*11111_` should generate the output `11111111111111111111`
|
||||
|
||||
**Ruleset 5:**
|
||||
|
||||
@ -164,13 +140,7 @@ B1 -> 1B
|
||||
1C1 -> H11
|
||||
</pre>
|
||||
|
||||
This ruleset should turn
|
||||
|
||||
`000000A000000`
|
||||
|
||||
into
|
||||
|
||||
`00011H1111000`
|
||||
This ruleset should turn `000000A000000` into `00011H1111000`
|
||||
|
||||
# --hints--
|
||||
|
||||
|
@ -12,11 +12,15 @@ Loop over multiple arrays and create a new array whose $i^{th}$ element is the c
|
||||
|
||||
For this example, if you are given this array of arrays:
|
||||
|
||||
`[ ["a", "b", "c"], ["A", "B", "C"], [1, 2, 3] ]`
|
||||
```js
|
||||
[ ["a", "b", "c"], ["A", "B", "C"], [1, 2, 3] ]
|
||||
```
|
||||
|
||||
the output should be:
|
||||
|
||||
`["aA1","bB2","cC3"]`
|
||||
```js
|
||||
["aA1","bB2","cC3"]
|
||||
```
|
||||
|
||||
# --instructions--
|
||||
|
||||
|
@ -14,7 +14,9 @@ Make your function work with the following list of values and set of indices:
|
||||
|
||||
<code>values: [7, <b>6</b>, 5, 4, 3, 2, <b>1</b>, <b>0</b>]</code>
|
||||
|
||||
`indices(0-based): {6, 1, 7}`
|
||||
```js
|
||||
indices(0-based): {6, 1, 7}
|
||||
```
|
||||
|
||||
Where the correct result would be:
|
||||
|
||||
|
@ -32,7 +32,9 @@ testData1 = [
|
||||
|
||||
One could rank top 10 employees in each department by calling:
|
||||
|
||||
`topRankPerGroup(10, testData1, 'dept', 'salary')`
|
||||
```js
|
||||
topRankPerGroup(10, testData1, 'dept', 'salary')
|
||||
```
|
||||
|
||||
Given the following data:
|
||||
|
||||
@ -48,7 +50,9 @@ testData2 = [
|
||||
|
||||
One could rank the top-rated movie in each genre by calling:
|
||||
|
||||
`topRankPerGroup(1, testData2, 'genre', 'rating')`
|
||||
```js
|
||||
topRankPerGroup(1, testData2, 'genre', 'rating')
|
||||
```
|
||||
|
||||
The function should return an array with an array for each group containing the top `n` objects.
|
||||
|
||||
|
Reference in New Issue
Block a user