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

@ -44,9 +44,9 @@ tests:
```js
function bubbleSort(array) {
// change code below this line
// Only change code below this line
return array;
// change code above this line
// Only change code above this line
}
bubbleSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);

View File

@ -42,9 +42,9 @@ tests:
```js
function insertionSort(array) {
// change code below this line
// Only change code below this line
return array;
// change code above this line
// Only change code above this line
}
insertionSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);

View File

@ -46,10 +46,9 @@ tests:
```js
function mergeSort(array) {
// change code below this line
// change code above this line
// Only change code below this line
return array;
// Only change code above this line
}
mergeSort([1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]);

View File

@ -10,7 +10,6 @@ forumTopicId: 301615
Here we will move on to an intermediate sorting algorithm: quick sort. Quick sort is an efficient, recursive divide-and-conquer approach to sorting an array. In this method, a pivot value is chosen in the original array. The array is then partitioned into two subarrays of values less than and greater than the pivot value. We then combine the result of recursively calling the quick sort algorithm on both sub-arrays. This continues until the base case of an empty or single-item array is reached, which we return. The unwinding of the recursive calls return us the sorted array.
Quick sort is a very efficient sorting method, providing <i>O(nlog(n))</i> performance on average. It is also relatively easy to implement. These attributes make it a popular and useful sorting method.
<strong>Instructions:</strong> Write a function <code>quickSort</code> which takes an array of integers as input and returns an array of these integers in sorted order from least to greatest. While the choice of the pivot value is important, any pivot will do for our purposes here. For simplicity, the first or last element could be used.
<strong>Note:</strong><br>We are calling this function from behind the scenes; the test array we are using is commented out in the editor. Try logging <code>array</code> to see your sorting algorithm in action!
</section>
## Instructions
@ -27,7 +26,7 @@ tests:
testString: assert(typeof quickSort == 'function');
- text: <code>quickSort</code> should return a sorted array (least to greatest).
testString: assert(isSorted(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])));
- text: <code>quickSort</code> should return an array that is unchanged except for order.
- text: <code>quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92])</code> should return an array that is unchanged except for order.
testString: assert.sameMembers(quickSort([1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]), [1,4,2,8,345,123,43,32,5643,63,123,43,2,55,1,234,92]);
- text: <code>quickSort</code> should not use the built-in <code>.sort()</code> method.
testString: assert(isBuiltInSortUsed());
@ -43,14 +42,10 @@ tests:
```js
function quickSort(array) {
// change code below this line
// change code above this line
// Only change code below this line
return array;
// Only change code above this line
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
```
</div>
@ -106,9 +101,6 @@ function quickSort(array) {
return [...quickSort(lesser), ...equal, ...quickSort(greater)];
}
}
// test array:
// [1, 4, 2, 8, 345, 123, 43, 32, 5643, 63, 123, 43, 2, 55, 1, 234, 92]
```
</section>

View File

@ -42,9 +42,9 @@ tests:
```js
function selectionSort(array) {
// change code below this line
// Only change code below this line
return array;
// change code above this line
// Only change code above this line
}

View File

@ -44,7 +44,6 @@ tests:
```js
function updateInventory(arr1, arr2) {
// All inventory must be accounted for or you're fired!
return arr1;
}

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>

View File

@ -61,7 +61,6 @@ primeSummation(2000000);
<section id='solution'>
```js
//noprotect
function primeSummation(n) {
if (n < 3) { return 0 };
let nums = [0, 0, 2];

View File

@ -59,11 +59,9 @@ tests:
```js
function fiboEvenSum(n) {
// You can do it!
return true;
}
fiboEvenSum(10);
```
</div>

View File

@ -132,8 +132,6 @@ function replaceChar(origString, replaceChar, index) {
```js
// noprotect
function solve24(numStr) {
const digitsArr = numStr.split('');
const answers = [];

View File

@ -64,7 +64,6 @@ function emirps(n) {
```js
// noprotect
function emirps(num, showEmirps)
{
const is_prime = function(n)

View File

@ -65,7 +65,6 @@ function primeGenerator(num, showPrimes) {
```js
// noprotect
function primeGenerator(num, showPrimes) {
let i,
arr = [];

View File

@ -50,7 +50,6 @@ tests:
<div id='js-seed'>
```js
// noprotect
function hailstoneSequence() {
const res = [];
@ -78,7 +77,6 @@ const res = [[27, 82, 41, 124, 8, 4, 2, 1], [351, 77031]];
```js
// noprotect
function hailstoneSequence () {
const res = [];

View File

@ -43,7 +43,7 @@ function isHarshadOrNiven() {
firstTwenty: [],
firstOver1000: undefined
};
// Change after this line
// Only change code below this line
return res;
}

View File

@ -50,7 +50,6 @@ tests:
<div id='js-seed'>
```js
// noprotect
function heronianTriangle(n) {
@ -84,7 +83,6 @@ const res = [
```js
// noprotect
function heronianTriangle(n) {
const list = [];
const result = [];

View File

@ -71,7 +71,6 @@ tests:
<div id='js-seed'>
```js
// noprotect
function ffr(n) {
return n;
}
@ -102,7 +101,6 @@ const ffsParamRes = [[10, 14], [50, 59], [100, 112], [1000, 1041]];
```js
// noprotect
const R = [null, 1];
const S = [null, 2];

View File

@ -51,7 +51,6 @@ tests:
<div id='js-seed'>
```js
// noprotect
function splitCoconuts(intSailors) {
return true;
@ -69,7 +68,6 @@ function splitCoconuts(intSailors) {
```js
// noprotect
function splitCoconuts(intSailors) {
let intNuts = intSailors;
let result = splitCoconutsHelper(intNuts, intSailors);