fix(curriculum): Consolidated comments for JavaScript Algorithms and Data Structures challenges - part 2 of 4 (#38259)

This commit is contained in:
Randell Dawson
2020-03-02 23:18:30 -08:00
committed by GitHub
parent 012e5c848b
commit 6a7a7e6d7d
69 changed files with 111 additions and 141 deletions

View File

@ -63,9 +63,9 @@ tests:
```js
let myArray = ["a", "b", "c", "d"];
// change code below this line
// Only change code below this line
//change code above this line
// Only change code above this line
console.log(myArray);
```

View File

@ -56,14 +56,13 @@ let foods = {
grapes: 35,
strawberries: 27
};
// do not change code above this line
function checkInventory(scannedItem) {
// change code below this line
// Only change code below this line
// Only change code above this line
}
// change code below this line to test different cases:
console.log(checkInventory("apples"));
```

View File

@ -51,13 +51,12 @@ tests:
```js
function mixedNumbers(arr) {
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
return arr;
}
// do not change code below this line
console.log(mixedNumbers(['IV', 5, 'six']));
```
@ -72,10 +71,8 @@ console.log(mixedNumbers(['IV', 5, 'six']));
```js
function mixedNumbers(arr) {
// change code below this line
arr.push(7,'VIII',9);
arr.unshift('I',2,'three');
// change code above this line
return arr;
}
```

View File

@ -53,13 +53,12 @@ tests:
```js
function htmlColorNames(arr) {
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
return arr;
}
// do not change code below this line
console.log(htmlColorNames(['DarkGoldenRod', 'WhiteSmoke', 'LavenderBlush', 'PaleTurquoise', 'FireBrick']));
```

View File

@ -72,9 +72,9 @@ let foods = {
plums: 28
};
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
console.log(foods);
```
@ -95,11 +95,9 @@ let foods = {
plums: 28
};
// change code below this line
foods['bananas'] = 13;
foods['grapes'] = 35;
foods['strawberries'] = 27;
// change code above this line
```
</section>

View File

@ -52,12 +52,11 @@ tests:
```js
function quickCheck(arr, elem) {
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
}
// change code here to test different cases:
console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
```
@ -72,9 +71,7 @@ console.log(quickCheck(['squash', 'onions', 'shallots'], 'mushrooms'));
```js
function quickCheck(arr, elem) {
// change code below this line
return arr.indexOf(elem) >= 0;
// change code above this line
}
```

View File

@ -69,9 +69,9 @@ let users = {
};
function isEveryoneHere(obj) {
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
}
console.log(isEveryoneHere(users));

View File

@ -46,11 +46,10 @@ tests:
```js
function spreadOut() {
let fragment = ['to', 'code'];
let sentence; // change this line
let sentence; // Change this line
return sentence;
}
// do not change code below this line
console.log(spreadOut());
```

View File

@ -53,15 +53,14 @@ tests:
function copyMachine(arr, num) {
let newArr = [];
while (num >= 1) {
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
num--;
}
return newArr;
}
// change code here to test different cases:
console.log(copyMachine([true, false, true], 2));
```
@ -85,9 +84,7 @@ const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
function copyMachine(arr,num){
let newArr=[];
while(num >=1){
// change code below this line
newArr.push([...arr]);
//change code above this line
num--;
}
return newArr;

View File

@ -46,12 +46,12 @@ tests:
```js
function forecast(arr) {
// change code below this line
// Only change code below this line
return arr;
}
// do not change code below this line
// Only change code above this line
console.log(forecast(['cold', 'rainy', 'warm', 'sunny', 'cool', 'thunderstorms']));
```

View File

@ -80,13 +80,13 @@ tests:
```js
let myNestedArray = [
// change code below this line
// Only change code below this line
['unshift', false, 1, 2, 3, 'complex', 'nested'],
['loop', 'shift', 6, 7, 1000, 'method'],
['concat', false, true, 'spread', 'array'],
['mutate', 1327.98, 'splice', 'slice', 'push'],
['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth']
// change code above this line
// Only change code above this line
];
```
@ -101,13 +101,11 @@ let myNestedArray = [
```js
let myNestedArray = [
// change code below this line
['unshift', ['deep', ['deeper', ['deepest']]],false, 1, 2, 3, 'complex', 'nested'],
['loop', 'shift', 6, 7, 1000, 'method'],
['concat', false, true, 'spread', 'array'],
['mutate', 1327.98, 'splice', 'slice', 'push'],
['iterate', 1.3849, 7, '8.4876', 'arbitrary', 'depth']
// change code above this line
];
```

View File

@ -55,9 +55,9 @@ let users = {
};
function getArrayOfUsers(obj) {
// change code below this line
// Only change code below this line
// change code above this line
// Only change code above this line
}
console.log(getArrayOfUsers(users));

View File

@ -58,12 +58,11 @@ tests:
```js
function popShift(arr) {
let popped; // change this line
let shifted; // change this line
let popped; // Change this line
let shifted; // Change this line
return [shifted, popped];
}
// do not change code below this line
console.log(popShift(['challenge', 'is', 'not', 'complete']));
```
@ -78,8 +77,8 @@ console.log(popShift(['challenge', 'is', 'not', 'complete']));
```js
function popShift(arr) {
let popped = arr.pop(); // change this line
let shifted = arr.shift(); // change this line
let popped = arr.pop(); // Change this line
let shifted = arr.shift(); // Change this line
return [shifted, popped];
}
```

View File

@ -60,9 +60,9 @@ tests:
```js
const arr = [2, 4, 5, 1, 7, 5, 2, 1];
// only change code below this line
// Only change code below this line
// only change code above this line
// Only change code above this line
console.log(arr);
```

View File

@ -76,7 +76,7 @@ tests:
<div id='js-seed'>
```js
let yourArray; // change this line
let yourArray; // Change this line
```
</div>

View File

@ -54,7 +54,7 @@ var ourData = ourArray[0]; // equals 50
// Setup
var myArray = [50,60,70];
// Only change code below this line.
// Only change code below this line
```

View File

@ -54,7 +54,7 @@ tests:
// Setup
var myArray = [[1,2,3], [4,5,6], [7,8,9], [[10,11,12], 13, 14]];
// Only change code below this line.
// Only change code below this line
var myData = myArray[0][0];
```

View File

@ -77,7 +77,7 @@ var testObj = {
19: "Unitas"
};
// Only change code below this line;
// Only change code below this line
var playerNumber; // Change this Line
var player = testObj; // Change this Line

View File

@ -59,7 +59,7 @@ var myDog = {
"friends": ["freeCodeCamp Campers"]
};
// Only change code below this line.
// Only change code below this line
```

View File

@ -75,7 +75,7 @@ var ourDog = {
"friends": ["everything!"]
};
// Only change code below this line.
// Only change code below this line
var myDog = {

View File

@ -70,7 +70,6 @@ function testGreaterThan(val) {
return "10 or Under";
}
// Change this value to test
testGreaterThan(10);
```

View File

@ -56,12 +56,10 @@ var a = 3;
var b = 17;
var c = 12;
// Only modify code below this line
// Only change code below this line
a = a + 12;
b = 9 + b;
c = c + 7;
```
</div>

View File

@ -49,12 +49,10 @@ var a = 48;
var b = 108;
var c = 33;
// Only modify code below this line
// Only change code below this line
a = a / 12;
b = b / 4;
c = c / 11;
```
</div>

View File

@ -49,13 +49,10 @@ var a = 5;
var b = 12;
var c = 4.6;
// Only modify code below this line
// Only change code below this line
a = a * 5;
b = 3 * b;
c = c * 10;
```
</div>

View File

@ -49,13 +49,10 @@ var a = 11;
var b = 9;
var c = 3;
// Only modify code below this line
// Only change code below this line
a = a - 6;
b = b - 15;
c = c - 1;
```
</div>

View File

@ -60,7 +60,7 @@ for (var i = 10; i > 0; i -= 2) {
// Setup
var myArray = [];
// Only change code below this line.
// Only change code below this line
```

View File

@ -25,7 +25,7 @@ creates a <code>variable</code> called <code>ourName</code>. In JavaScript we en
## Instructions
<section id='instructions'>
Use the <code>var</code> keyword to create a variable called <code>myName</code>.
<strong>Hint</strong><br>Look at the <code>ourName</code> example if you get stuck.
<strong>Hint</strong><br>Look at the <code>ourName</code> example above if you get stuck.
</section>
## Tests
@ -46,10 +46,7 @@ tests:
<div id='js-seed'>
```js
// Example
var ourName;
// Declare myName below this line
```

View File

@ -57,7 +57,7 @@ var myDog = {
"bark": "woof"
};
// Only change code below this line.
// Only change code below this line
```

View File

@ -38,7 +38,7 @@ tests:
<div id='js-seed'>
```js
var quotient = 0.0 / 2.0; // Fix this line
var quotient = 0.0 / 2.0; // Change this line
```
</div>

View File

@ -50,7 +50,7 @@ firstNameLength = firstName.length;
var lastNameLength = 0;
var lastName = "Lovelace";
// Only change code below this line.
// Only change code below this line
lastNameLength = lastName;

View File

@ -42,11 +42,11 @@ tests:
```js
function randomFraction() {
// Only change code below this line.
// Only change code below this line
return 0;
// Only change code above this line.
// Only change code above this line
}
```

View File

@ -49,7 +49,7 @@ var randomNumberBetween0and19 = Math.floor(Math.random() * 20);
function randomWholeNum() {
// Only change code below this line.
// Only change code below this line
return Math.random();
}

View File

@ -51,7 +51,7 @@ function ourRandomRange(ourMin, ourMax) {
ourRandomRange(1, 9);
// Only change code below this line.
// Only change code below this line
function randomRange(myMin, myMax) {

View File

@ -14,7 +14,7 @@ Variables which are used without the <code>var</code> keyword are automatically
## Instructions
<section id='instructions'>
Using <code>var</code>, declare a <code>global</code> variable <code>myGlobal</code> outside of any function. Initialize it with a value of <code>10</code>.
Using <code>var</code>, declare a global variable named <code>myGlobal</code> outside of any function. Initialize it with a value of <code>10</code>.
Inside function <code>fun1</code>, assign <code>5</code> to <code>oopsGlobal</code> <strong><em>without</em></strong> using the <code>var</code> keyword.
</section>
@ -42,7 +42,7 @@ tests:
<div id='js-seed'>
```js
// Declare your variable here
// Declare the myGlobal variable below this line
function fun1() {
@ -51,6 +51,7 @@ function fun1() {
}
// Only change code above this line
function fun2() {
var output = "";
if (typeof myGlobal != "undefined") {
@ -112,15 +113,12 @@ uncapture();
```js
// Declare your variable here
var myGlobal = 10;
function fun1() {
// Assign 5 to oopsGlobal Here
oopsGlobal = 5;
}
// Only change code above this line
function fun2() {
var output = "";
if(typeof myGlobal != "undefined") {

View File

@ -57,7 +57,7 @@ for (var i = 0; i < 10; i += 2) {
// Setup
var myArray = [];
// Only change code below this line.
// Only change code below this line
```

View File

@ -62,7 +62,7 @@ for (var i = 0; i < 5; i++) {
// Setup
var myArray = [];
// Only change code below this line.
// Only change code below this line
```

View File

@ -53,7 +53,7 @@ tests:
// Setup
var myArray = [];
// Only change code below this line.
// Only change code below this line
```

View File

@ -51,7 +51,9 @@ tests:
```js
function myLocalScope() {
'use strict'; // you shouldn't need to edit this line
'use strict';
// Only change code below this line
console.log(myVar);
}

View File

@ -56,7 +56,7 @@ var removedFromOurArray = ourArray.pop();
// Setup
var myArray = [["John", 23], ["cat", 2]];
// Only change code below this line.
// Only change code below this line
var removedFromMyArray;

View File

@ -50,7 +50,7 @@ ourArray.push(["happy", "joy"]);
// Setup
var myArray = [["John", 23], ["cat", 2]];
// Only change code below this line.
// Only change code below this line
```

View File

@ -45,7 +45,7 @@ var removedFromOurArray = ourArray.shift();
// Setup
var myArray = [["John", 23], ["dog", 3]];
// Only change code below this line.
// Only change code below this line
var removedFromMyArray;
@ -72,7 +72,7 @@ var removedFromMyArray;
```js
var myArray = [["John", 23], ["dog", 3]];
// Only change code below this line.
// Only change code below this line
var removedFromMyArray = myArray.shift();
```

View File

@ -45,7 +45,7 @@ ourArray.unshift("Happy");
var myArray = [["John", 23], ["dog", 3]];
myArray.shift();
// Only change code below this line.
// Only change code below this line
```

View File

@ -51,7 +51,7 @@ ourArray[1] = 45; // ourArray now equals [18,45,99].
// Setup
var myArray = [18,64,99];
// Only change code below this line.
// Only change code below this line
```

View File

@ -37,7 +37,7 @@ tests:
// Example
var ourArray = [["the universe", 42], ["everything", 101010]];
// Only change code below this line.
// Only change code below this line
var myArray = [];
```

View File

@ -59,7 +59,6 @@ function multiplyAll(arr) {
return product;
}
// Modify values below to test your code
multiplyAll([[1,2],[3,4],[5,6,7]]);
```

View File

@ -57,7 +57,7 @@ function ourFunctionWithArgs(a, b) {
}
ourFunctionWithArgs(10, 5); // Outputs 5
// Only change code below this line.
// Only change code below this line
```

View File

@ -49,7 +49,7 @@ tests:
<div id='js-seed'>
```js
//Setup
// Setup
var contacts = [
{
"firstName": "Akira",

View File

@ -68,7 +68,6 @@ function abTest(a, b) {
return Math.round(Math.pow(Math.sqrt(a) + Math.sqrt(b), 2));
}
// Change values below to test your code
abTest(2,2);
```

View File

@ -59,12 +59,13 @@ tests:
```js
function isLess(a, b) {
// Fix this code
// Only change code below this line
if (a < b) {
return true;
} else {
return false;
}
// Only change code above this line
}
// Change these values to test

View File

@ -46,17 +46,20 @@ tests:
```js
function nextInLine(arr, item) {
// Your code here
// Only change code below this line
return item;
// Only change code above this line
return item; // Change this line
}
// Test Setup
// Setup
var testArr = [1,2,3,4,5];
// Display Code
// Display code
console.log("Before: " + JSON.stringify(testArr));
console.log(nextInLine(testArr, 6)); // Modify this line to test
console.log(nextInLine(testArr, 6));
console.log("After: " + JSON.stringify(testArr));
```

View File

@ -44,7 +44,7 @@ tests:
// Example
var ourArray = ["John", 23];
// Only change code below this line.
// Only change code below this line
var myArray = [];
```

View File

@ -62,7 +62,6 @@ function checkObj(checkProp) {
return "Change Me!";
}
// Test your code by modifying these values
checkObj("gift");
```

View File

@ -54,9 +54,8 @@ tests:
var myStr = "Jello World";
// Only change code below this line
myStr[0] = "H"; // Fix Me
myStr[0] = "H"; // Change this line
// Only change code above this line
```

View File

@ -39,11 +39,11 @@ tests:
```js
function welcomeToBooleans() {
// Only change code below this line.
// Only change code below this line
return false; // Change this line
// Only change code above this line.
// Only change code above this line
}
```

View File

@ -55,12 +55,12 @@ tests:
<div id='js-seed'>
```js
// Declarations
// Variable declarations
var StUdLyCapVaR;
var properCamelCase;
var TitleCaseOver;
// Assignments
// Variable assignments
STUDLYCAPVAR = 10;
PRoperCAmelCAse = "A String";
tITLEcASEoVER = 9000;

View File

@ -40,17 +40,15 @@ tests:
<div id='js-seed'>
```js
// Initialize these three variables
// Only change code below this line
var a;
var b;
var c;
// Do not change code below this line
// Only change code above this line
a = a + 1;
b = b + 5;
c = c + " String!";
```
</div>

View File

@ -69,7 +69,7 @@ var myDog = {
"friends": ["freeCodeCamp Campers"]
};
// Only change code below this line.
// Only change code below this line
```

View File

@ -45,7 +45,7 @@ var lastLetterOfFirstName = firstName[firstName.length - 1];
// Setup
var lastName = "Lovelace";
// Only change code below this line.
// Only change code below this line
var lastLetterOfLastName = lastName;

View File

@ -45,7 +45,7 @@ var secondLetterOfFirstName = firstName[1];
// Setup
var lastName = "Lovelace";
// Only change code below this line.
// Only change code below this line
var thirdLetterOfLastName = lastName;

View File

@ -70,11 +70,11 @@ function ourTrueOrFalse(isItTrue) {
// Setup
function trueOrFalse(wasThatTrue) {
// Only change code below this line.
// Only change code below this line
// Only change code above this line.
// Only change code above this line
}

View File

@ -67,10 +67,11 @@ tests:
```js
//Only change code below this line
// Only change code below this line
function countdown(n){
return;
}
// Only change code above this line
console.log(countdown(5)); // [5, 4, 3, 2, 1]
```
@ -91,7 +92,6 @@ const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
<section id='solution'>
```js
//Only change code below this line
function countdown(n){
return n < 1 ? [] : [n].concat(countdown(n - 1));
}

View File

@ -54,8 +54,9 @@ var myAdjective = "big";
var myVerb = "ran";
var myAdverb = "quickly";
var wordBlanks = ""; // Only change this line;
// Only change code below this line
var wordBlanks = ""; // Change this line
// Only change code above this line
```
</div>

View File

@ -61,9 +61,9 @@ tests:
function countToFive() {
let firstFive = "12345";
let len = firstFive.length;
// Fix the line below
// Only change code below this line
for (let i = 1; i <= len; i++) {
// Do not alter code below this line
// Only change code above this line
console.log(firstFive[i]);
}
}
@ -84,9 +84,9 @@ countToFive();
function countToFive() {
let firstFive = "12345";
let len = firstFive.length;
// Fix the line below
// Only change code below this line
for (let i = 0; i < len; i++) {
// Do not alter code below this line
// Only change code above this line
console.log(firstFive[i]);
}
}

View File

@ -50,9 +50,9 @@ const makeServerRequest = new Promise((resolve, reject) => {
let responseFromServer;
if(responseFromServer) {
// change this line
// Change this line
} else {
// change this line
// Change this line
}
});
```

View File

@ -62,7 +62,7 @@ tests:
const arr1 = ['JAN', 'FEB', 'MAR', 'APR', 'MAY'];
let arr2;
arr2 = []; // change this line
arr2 = []; // Change this line
console.log(arr2);
```

View File

@ -65,7 +65,7 @@ var myConcat = function(arr1, arr2) {
"use strict";
return arr1.concat(arr2);
};
// test your code
console.log(myConcat([1, 2], [3, 4, 5]));
```
@ -83,7 +83,7 @@ const myConcat = (arr1, arr2) => {
"use strict";
return arr1.concat(arr2);
};
// test your code
console.log(myConcat([1, 2], [3, 4, 5]));
```

View File

@ -44,12 +44,11 @@ tests:
```js
const squareList = (arr) => {
// only change code below this line
// Only change code below this line
return arr;
// only change code above this line
// Only change code above this line
};
// test your code
const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);
```

View File

@ -59,7 +59,7 @@ function Dog(name) {
this.name = name;
}
// Modify the code below this line
// Only change code below this line
Dog.prototype = {
numLegs: 4,

View File

@ -55,7 +55,10 @@ tests:
<div id='js-seed'>
```js
let chewieRegex = /change/; // Only change this line
// Only change code below this line
let chewieRegex = /change/; // Change this line
// Only change code above this line
let result = chewieQuote.match(chewieRegex);
```