fix(learn): Consolidated comments for Coding Interview Prep challenges - part 2 of 2 (#39576)

* fix: consolidate comments for use with the translation dictionary

* fix: added blank line between comments

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>

* fix: removed unneeded comment

Co-authored-by: Tom <20648924+moT01@users.noreply.github.com>
This commit is contained in:
Randell Dawson
2020-09-15 12:31:21 -07:00
committed by GitHub
parent 8788ad946b
commit 876d9f3994
50 changed files with 141 additions and 160 deletions

View File

@ -53,8 +53,9 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```

View File

@ -56,7 +56,6 @@ tests:
```js
function bfs(graph, root) {
// Distance object returned
var nodesLen = {};
return nodesLen;
@ -112,7 +111,6 @@ function isEquivalent(a, b) {
```js
function bfs(graph, root) {
// Distance object returned
var nodesLen = {};
// Set all distances to infinity
for (var i = 0; i < graph.length; i++) {

View File

@ -49,8 +49,9 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```

View File

@ -47,8 +47,9 @@ function BinarySearchTree() {
this.root = null;
}
function isBinarySearchTree(tree) {
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```

View File

@ -56,8 +56,9 @@ var Node = function(data, prev) {
var DoublyLinkedList = function() {
this.head = null;
this.tail = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
};
```

View File

@ -59,8 +59,9 @@ var hash = string => {
};
var HashTable = function() {
this.collection = {};
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
};
```
@ -105,7 +106,7 @@ var hash = (string) => {
};
var HashTable = function() {
this.collection = {};
// change code below this line
// Only change code below this line
this.add = function(key, val) {
var theHash = hash(key);
@ -133,7 +134,7 @@ var HashTable = function() {
}
return null
}
// change code above this line
// Only change code above this line
};
```

View File

@ -58,8 +58,9 @@ tests:
```js
var Map = function() {
this.collection = {};
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
};
```
@ -72,7 +73,7 @@ var Map = function() {
```js
var Map = function() {
this.collection = {};
// change code below this line
// Only change code below this line
this.add = function(key,value) {
this.collection[key] = value;
@ -103,7 +104,7 @@ var Map = function() {
delete this.collection[item];
}
}
// change code above this line
// Only change code above this line
};
```

View File

@ -82,20 +82,14 @@ class Set {
return this.dictionary[element] !== undefined;
}
// This method will return all the values in the set as an array
// This method will return all the values in the set
values() {
return Object.keys(this.dictionary);
}
// change code below this line
// Only change code below this line
// write your add method here
// write your remove method here
// write your size method here
// change code above this line
// Only change code above this line
}
```

View File

@ -57,8 +57,9 @@ var Node = function() {
};
};
var Trie = function() {
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
};
```

View File

@ -43,7 +43,7 @@ tests:
<div id='js-seed'>
```js
// change code below this line
```
</div>

View File

@ -54,9 +54,9 @@ tests:
```js
function checkSet() {
var set = new Set([1, 2, 3, 3, 2, 1, 2, 3, 1]);
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
console.log(Array.from(set));
return set;
}

View File

@ -58,7 +58,7 @@ function Node(value) {
function BinarySearchTree() {
this.root = null;
// case 1: target has no children, change code below this line
// Only change code below this line
}
```

View File

@ -61,7 +61,7 @@ function BinarySearchTree() {
}
var target;
var parent = null;
// find the target value and its parent
// Find the target value and its parent
(function findValue(node = this.root) {
if (value == node.value) {
target = node;
@ -80,10 +80,10 @@ function BinarySearchTree() {
if (target === null) {
return null;
}
// count the children of the target to delete
// Count the children of the target to delete
var children =
(target.left !== null ? 1 : 0) + (target.right !== null ? 1 : 0);
// case 1: target has no children
// Case 1: Target has no children
if (children === 0) {
if (target == this.root) {
this.root = null;
@ -95,7 +95,8 @@ function BinarySearchTree() {
}
}
}
// case 2: target has one child, change code below this line
// Case 2: Target has one child
// Only change code below this line
};
}
```

View File

@ -66,7 +66,7 @@ function BinarySearchTree() {
}
var target;
var parent = null;
// find the target value and its parent
// Find the target value and its parent
(function findValue(node = this.root) {
if (value == node.value) {
target = node;
@ -85,10 +85,10 @@ function BinarySearchTree() {
if (target === null) {
return null;
}
// count the children of the target to delete
// Count the children of the target to delete
var children =
(target.left !== null ? 1 : 0) + (target.right !== null ? 1 : 0);
// case 1: target has no children
// Case 1: Target has no children
if (children === 0) {
if (target == this.root) {
this.root = null;
@ -100,7 +100,7 @@ function BinarySearchTree() {
}
}
}
// case 2: target has one child
// Case 2: Target has one child
else if (children == 1) {
var newChild = target.left !== null ? target.left : target.right;
if (parent === null) {
@ -114,7 +114,8 @@ function BinarySearchTree() {
}
target = null;
}
// case 3: target has two children, change code below this line
// Case 3: Target has two children
// Only change code below this line
};
}
```

View File

@ -55,8 +55,9 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```
@ -117,8 +118,9 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
this.findMinHeight = function(root = this.root) {
// empty tree.
if (root === null) {

View File

@ -50,8 +50,9 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```

View File

@ -41,22 +41,22 @@ tests:
<div id='js-seed'>
```js
// check if array is sorted
function isSorted(a){
for(let i = 0; i < a.length - 1; i++)
if(a[i] > a[i + 1])
return false;
return true;
}
// generate a randomly filled array
// Generate a randomly filled array
var array = new Array();
(function createArray(size = 5) {
array.push(+(Math.random() * 100).toFixed(0));
return size > 1 ? createArray(size - 1) : undefined;
})(25);
var MinHeap = function() {
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
};
```

View File

@ -55,8 +55,9 @@ tests:
```js
var MaxHeap = function() {
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
};
```
@ -68,7 +69,7 @@ var MaxHeap = function() {
```js
var MaxHeap = function() {
// change code below this line
// Only change code below this line
this.heap = [null];
this.insert = (ele) => {
var index = this.heap.length;
@ -84,7 +85,7 @@ var MaxHeap = function() {
this.print = () => {
return this.heap.slice(1);
}
// change code above this line
// Only change code above this line
};
```

View File

@ -46,8 +46,9 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```
@ -127,7 +128,7 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// Only change code below this line
this.invert = function(node = this.root) {
if (node) {
const temp = node.left;
@ -138,7 +139,7 @@ function BinarySearchTree() {
}
return node;
}
// change code above this line
// Only change code above this line
}
```

View File

@ -42,15 +42,15 @@ class Set {
this.dictionary = {};
this.length = 0;
}
// this method will check for the presence of an element and return true or false
// This method will check for the presence of an element and return true or false
has(element) {
return this.dictionary[element] !== undefined;
}
// this method will return all the values in the set
// This method will return all the values in the set
values() {
return Object.keys(this.dictionary);
}
// this method will add an element to the set
// This method will add an element to the set
add(element) {
if (!this.has(element)) {
this.dictionary[element] = true;
@ -60,7 +60,7 @@ class Set {
return false;
}
// this method will remove an element from a set
// This method will remove an element from a set
remove(element) {
if (this.has(element)) {
delete this.dictionary[element];
@ -70,11 +70,11 @@ class Set {
return false;
}
// this method will return the size of the set
// This method will return the size of the set
size() {
return this.length;
}
// This is our union method from that lesson
// This is our union method
union(set) {
const newSet = new Set();
this.values().forEach(value => {
@ -86,7 +86,7 @@ class Set {
return newSet;
}
// This is our intersection method from that lesson
// This is our intersection method
intersection(set) {
const newSet = new Set();
@ -108,8 +108,9 @@ class Set {
return newSet;
}
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```

View File

@ -49,15 +49,15 @@ class Set {
this.dictionary = {};
this.length = 0;
}
// this method will check for the presence of an element and return true or false
// This method will check for the presence of an element and return true or false
has(element) {
return this.dictionary[element] !== undefined;
}
// this method will return all the values in the set
// This method will return all the values in the set
values() {
return Object.keys(this.dictionary);
}
// this method will add an element to the set
// This method will add an element to the set
add(element) {
if (!this.has(element)) {
this.dictionary[element] = true;
@ -67,7 +67,7 @@ class Set {
return false;
}
// this method will remove an element from a set
// This method will remove an element from a set
remove(element) {
if (this.has(element)) {
delete this.dictionary[element];
@ -77,11 +77,11 @@ class Set {
return false;
}
// this method will return the size of the set
// This method will return the size of the set
size() {
return this.length;
}
// This is our union method from that lesson
// This is our union method
union(set) {
const newSet = new Set();
this.values().forEach(value => {
@ -93,7 +93,7 @@ class Set {
return newSet;
}
// This is our intersection method from that lesson
// This is our intersection method
intersection(set) {
const newSet = new Set();
@ -115,7 +115,7 @@ class Set {
return newSet;
}
// This is our difference method from that lesson
difference(set) {
const newSet = new Set();
@ -127,8 +127,9 @@ class Set {
return newSet;
}
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```

View File

@ -40,15 +40,15 @@ class Set {
this.dictionary = {};
this.length = 0;
}
// this method will check for the presence of an element and return true or false
// This method will check for the presence of an element and return true or false
has(element) {
return this.dictionary[element] !== undefined;
}
// this method will return all the values in the set
// This method will return all the values in the set
values() {
return Object.keys(this.dictionary);
}
// this method will add an element to the set
// This method will add an element to the set
add(element) {
if (!this.has(element)) {
this.dictionary[element] = true;
@ -58,7 +58,7 @@ class Set {
return false;
}
// this method will remove an element from a set
// This method will remove an element from a set
remove(element) {
if (this.has(element)) {
delete this.dictionary[element];
@ -68,13 +68,13 @@ class Set {
return false;
}
// this method will return the size of the set
// This method will return the size of the set
size() {
return this.length;
}
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
}
```

View File

@ -41,15 +41,15 @@ class Set {
this.dictionary = {};
this.length = 0;
}
// this method will check for the presence of an element and return true or false
// This method will check for the presence of an element and return true or false
has(element) {
return this.dictionary[element] !== undefined;
}
// this method will return all the values in the set
// This method will return all the values in the set
values() {
return Object.keys(this.dictionary);
}
// this method will add an element to the set
// This method will add an element to the set
add(element) {
if (!this.has(element)) {
this.dictionary[element] = true;
@ -59,7 +59,7 @@ class Set {
return false;
}
// this method will remove an element from a set
// This method will remove an element from a set
remove(element) {
if (this.has(element)) {
delete this.dictionary[element];
@ -69,11 +69,11 @@ class Set {
return false;
}
// this method will return the size of the set
// This method will return the size of the set
size() {
return this.length;
}
// This is our union method from that lesson
// This is our union method
union(set) {
const newSet = new Set();
this.values().forEach(value => {
@ -85,8 +85,9 @@ class Set {
return newSet;
}
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```

View File

@ -61,9 +61,9 @@ var MaxHeap = function() {
this.print = () => {
return this.heap.slice(1);
}
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
};
```

View File

@ -52,7 +52,7 @@ function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){ // {1}
var Node = function(element){
this.element = element;
this.next = null;
};
@ -100,7 +100,7 @@ function LinkedList() {
var length = 0;
var head = null;
var Node = function (element) { // {1}
var Node = function (element) {
this.element = element;
this.next = null;
};

View File

@ -43,10 +43,7 @@ tests:
```js
function checkSet(){
var set = //Create a set with values 1, 2, 3, 4, & 5
//Remove the value 2
//Remove the value 5
//Return the set
var set = null;
return set;
}
```

View File

@ -49,8 +49,9 @@ var Node = function(data, prev) {
var DoublyLinkedList = function() {
this.head = null;
this.tail = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
};
```

View File

@ -55,7 +55,7 @@ function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){ // {1}
var Node = function(element){
this.element = element;
this.next = null;
};
@ -120,7 +120,7 @@ function LinkedList() {
var length = 0;
var head = null;
var Node = function(element){ // {1}
var Node = function(element){
this.element = element;
this.next = null;
};

View File

@ -40,13 +40,11 @@ tests:
```js
function checkSet(arrToBeSet, checkValue){
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
}
checkSet([ 1, 2, 3], 2); // Should return [ true, 3 ]
```
</div>

View File

@ -53,8 +53,9 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```
@ -114,7 +115,7 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// Only change code below this line
this.levelOrder = (root = this.root) => {
if(!root) return null;
let queue = [root];
@ -140,7 +141,7 @@ function BinarySearchTree() {
}
return results;
}
// change code above this line
// Only change code above this line
}
```

View File

@ -65,8 +65,9 @@ function Node(value) {
}
function BinarySearchTree() {
this.root = null;
// change code below this line
// change code above this line
// Only change code below this line
// Only change code above this line
}
```

View File

@ -44,9 +44,9 @@ tests:
```js
function checkSet(set){
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
}
```

View File

@ -44,10 +44,9 @@ var Kitten = new Node('Kitten');
var Puppy = new Node('Puppy');
Kitten.next = Puppy;
// only add code below this line
// Only change code below this line
// test your code
console.log(Kitten.next);
```
</div>