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

* fix: consolidate comments


Co-authored-by: Parth Parth <34807532+thecodingaviator@users.noreply.github.com>
This commit is contained in:
Randell Dawson
2020-03-08 07:46:28 -07:00
committed by GitHub
parent dbf3815fc7
commit 9252f96566
51 changed files with 121 additions and 178 deletions

View File

@ -67,16 +67,6 @@ tests:
<div id='js-seed'>
```js
// Example
var ourDog = {
"name": "Camper",
"legs": 4,
"tails": 1,
"friends": ["everything!"]
};
// Only change code below this line
var myDog = {

View File

@ -57,9 +57,9 @@ var myObj = {
};
function checkObj(checkProp) {
// Your Code Here
// Only change code below this line
return "Change Me!";
// Only change code above this line
}
checkObj("gift");

View File

@ -40,7 +40,7 @@ tests:
let a = 5;
let b = 1;
a++;
// Add your code below this line
// Only change code below this line
let sumAB = a + b;

View File

@ -50,7 +50,7 @@ tests:
let seven = 7;
let three = "3";
console.log(seven + three);
// Add your code below this line
// Only change code below this line
```

View File

@ -56,7 +56,7 @@ function editInPlace() {
'use strict';
// Only change code below this line
// s = [2, 5, 7]; <- this is invalid
// Using s = [2, 5, 7] would be invalid
// Only change code above this line
}

View File

@ -47,10 +47,9 @@ tests:
<div id='js-seed'>
```js
// Only change code below this line
const increment = (number, value) => number + value;
console.log(increment(5, 2)); // returns 7
console.log(increment(5)); // returns 6
// Only change code above this line
```
</div>

View File

@ -56,9 +56,6 @@ tests:
let a = 8, b = 6;
// Only change code below this line
// Only change code above this line
console.log(a); // should be 6
console.log(b); // should be 8
```
</div>

View File

@ -50,6 +50,8 @@ tests:
testString: assert(code.match(/(var|const|let)\s*{\s*today\s*:\s*{\s*(low\s*:\s*lowToday[^}]*|[^,]*,\s*low\s*:\s*lowToday\s*)}\s*}\s*=\s*LOCAL_FORECAST(;|\s+|\/\/)/g));
- text: You should use destructuring to create the <code>highToday</code> variable.
testString: assert(code.match(/(var|const|let)\s*{\s*today\s*:\s*{\s*(high\s*:\s*highToday[^}]*|[^,]*,\s*high\s*:\s*highToday\s*)}\s*}\s*=\s*LOCAL_FORECAST(;|\s+|\/\/)/g));
- text: <code>lowToday</code> should be equal to <code>64</code> and <code>highToday</code> should be equal to <code>77</code>.
testString: assert(lowToday === 64 && highToday === 77);
```
</section>
@ -71,9 +73,6 @@ const lowToday = LOCAL_FORECAST.today.low;
const highToday = LOCAL_FORECAST.today.high;
// Only change code above this line
console.log(lowToday); // should be 64
console.log(highToday); // should be 77
```
</div>
@ -88,11 +87,8 @@ const LOCAL_FORECAST = {
today: { low: 64, high: 77 },
tomorrow: { low: 68, high: 80 }
};
const { today: { low: lowToday, high: highToday }} = LOCAL_FORECAST;
console.log(highToday); // should be 77
console.log(highTomorrow); // should be 80
```
</section>

View File

@ -41,6 +41,8 @@ tests:
testString: assert(code.match(/(var|const|let)\s*{\s*(today\s*:\s*highToday[^}]*|[^,]*,\s*today\s*:\s*highToday\s*)}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
- text: You should use destructuring to create the <code>highTomorrow</code> variable.
testString: assert(code.match(/(var|const|let)\s*{\s*(tomorrow\s*:\s*highTomorrow[^}]*|[^,]*,\s*tomorrow\s*:\s*highTomorrow\s*)}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
- text: <code>highToday</code> should be equal to <code>77</code> and <code>highTomorrow</code> should be equal to <code>80</code>.
testString: assert(highToday === 77 && highTomorrow === 80);
```
</section>
@ -62,10 +64,6 @@ const highToday = HIGH_TEMPERATURES.today;
const highTomorrow = HIGH_TEMPERATURES.tomorrow;
// Only change code above this line
console.log(yesterday) // should be not defined
console.log(highToday); // should be 77
console.log(highTomorrow); // should be 80
```
</div>
@ -82,9 +80,6 @@ const HIGH_TEMPERATURES = {
};
const { today: highToday, tomorrow: highTomorrow } = HIGH_TEMPERATURES;
console.log(highToday); // should be 77
console.log(highTomorrow); // should be 80
```
</section>

View File

@ -46,6 +46,8 @@ tests:
testString: assert(code.match(/(var|let|const)\s*{\s*(today[^}]*|[^,]*,\s*today)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
- text: You should use destructuring to create the <code>tomorrow</code> variable.
testString: assert(code.match(/(var|let|const)\s*{\s*(tomorrow[^}]*|[^,]*,\s*tomorrow)\s*}\s*=\s*HIGH_TEMPERATURES(;|\s+|\/\/)/g));
- text: <code>today</code> should be equal to <code>77</code> and <code>tomorrow</code> should be equal to <code>80</code>.
testString: assert(today === 77 && tomorrow === 80);
```
</section>
@ -67,10 +69,6 @@ const today = HIGH_TEMPERATURES.today;
const tomorrow = HIGH_TEMPERATURES.tomorrow;
// Only change code above this line
console.log(yesterday) // should be not defined
console.log(today); // should be 77
console.log(tomorrow); // should be 80
```
</div>
@ -87,10 +85,6 @@ const HIGH_TEMPERATURES = {
};
const { today, tomorrow } = HIGH_TEMPERATURES;
console.log(yesterday) // should be not defined
console.log(today); // should be 77
console.log(tomorrow); // should be 80
```
</section>

View File

@ -67,13 +67,10 @@ const stats = {
average: 35.85
};
// Use function argument destructuring
// Only change code below this line
const half = (stats) => (stats.max + stats.min) / 2.0;
// Only change code above this line
console.log(stats); // should be object
console.log(half(stats)); // should be 28.015
```
</div>

View File

@ -32,6 +32,8 @@ Use destructuring assignment with the rest parameter to perform an effective <co
tests:
- text: <code>arr</code> should be <code>[3,4,5,6,7,8,9,10]</code>
testString: assert(arr.every((v, i) => v === i + 3) && arr.length === 8);
- text: <code>source</code> should be <code>[1,2,3,4,5,6,7,8,9,10]</code>
testString: assert(source.every((v, i) => v === i + 1) && source.length === 10);
- text: <code>Array.slice()</code> should not be used.
testString: getUserInput => assert(!getUserInput('index').match(/slice/g));
- text: Destructuring on <code>list</code> should be used.
@ -50,14 +52,13 @@ tests:
const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
"use strict";
// change code below this line
const arr = list; // change this
// change code above this line
// Only change code below this line
const arr = list; // Change this line
// Only change code above this line
return arr;
}
const arr = removeFirstTwo(source);
console.log(arr); // should be [3,4,5,6,7,8,9,10]
console.log(source); // should be [1,2,3,4,5,6,7,8,9,10];
```
</div>
@ -73,9 +74,7 @@ console.log(source); // should be [1,2,3,4,5,6,7,8,9,10];
const source = [1,2,3,4,5,6,7,8,9,10];
function removeFirstTwo(list) {
"use strict";
// change code below this line
const [, , ...arr] = list;
// change code above this line
return arr;
}
const arr = removeFirstTwo(source);

View File

@ -79,10 +79,10 @@ tests:
// Only change code above this line
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C
const thermos = new Thermostat(76); // Setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in Celsius
thermos.temperature = 26;
temp = thermos.temperature; // 26 in C
temp = thermos.temperature; // 26 in Celsius
```
</div>
@ -107,10 +107,10 @@ class Thermostat {
}
}
const thermos = new Thermostat(76); // setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in C
const thermos = new Thermostat(76); // Setting in Fahrenheit scale
let temp = thermos.temperature; // 24.44 in Celsius
thermos.temperature = 26;
temp = thermos.temperature; // 26 in C
temp = thermos.temperature; // 26 in Celsius
```
</section>

View File

@ -62,7 +62,6 @@ const createPerson = (name, age, gender) => {
};
// Only change code above this line
};
console.log(createPerson("Zodiac Hasbro", 56, "male")); // returns a proper object
```
</div>

View File

@ -52,10 +52,10 @@ tests:
```js
function nonMutatingPush(original, newItem) {
// Add your code below this line
// Only change code below this line
return original.push(newItem);
// Add your code above this line
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];

View File

@ -49,15 +49,15 @@ tests:
<div id='js-seed'>
```js
// the global variable
// The global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
// Only change code below this line
function urlSlug(title) {
}
// Add your code above this line
// Only change code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
```
@ -72,16 +72,13 @@ var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
<section id='solution'>
```js
// the global variable
// The global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
// Only change code below this line
function urlSlug(title) {
return title.trim().split(/\s+/).join("-").toLowerCase();
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
```
</section>

View File

@ -40,14 +40,14 @@ tests:
<div id='js-seed'>
```js
// the global variable
// The global variable
var fixedValue = 4;
function incrementer () {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
var newValue = incrementer(); // Should equal 5

View File

@ -52,10 +52,10 @@ tests:
```js
function sentensify(str) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
sentensify("May-the-force-be-with-you");
```
@ -71,9 +71,9 @@ sentensify("May-the-force-be-with-you");
```js
function sentensify(str) {
// Add your code below this line
// Only change code below this line
return str.split(/\W/).join(' ');
// Add your code above this line
// Only change code above this line
}
```

View File

@ -46,10 +46,10 @@ tests:
```js
function nonMutatingConcat(original, attach) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
@ -67,9 +67,9 @@ nonMutatingConcat(first, second);
```js
function nonMutatingConcat(original, attach) {
// Add your code below this line
// Only change code below this line
return original.concat(attach);
// Add your code above this line
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];

View File

@ -38,14 +38,14 @@ tests:
<div id='js-seed'>
```js
// the global Array
// The global variable
var s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback){
var newArray = [];
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
return newArray;
};
@ -70,11 +70,11 @@ var s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback){
var newArray = [];
// Add your code below this line
// Only change code below this line
for (var elem of this) {
newArray.push(callback(elem));
}
// Add your code above this line
// Only change code above this line
return newArray;
};

View File

@ -36,14 +36,13 @@ tests:
<div id='js-seed'>
```js
// the global Array
// The global variable
var s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback){
// Only change code below this line
var newArray = [];
// Add your code below this line
// Add your code above this line
// Only change code above this line
return newArray;
};
@ -68,12 +67,12 @@ var s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback){
var newArray = [];
// Add your code below this line
// Only change code below this line
for (let i = 0;i<this.length;i++) {
if (callback(this[i]))
newArray.push(this[i]);
}
// Add your code above this line
// Only change code above this line
return newArray;
};

View File

@ -81,10 +81,10 @@ tests:
```js
function add(x) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
add(10)(20)(30);
```

View File

@ -62,8 +62,6 @@ const getTea = (numOfCups) => {
// Only change code below this line
const tea4TeamFCC = null;
// Only change code above this line
console.log(tea4TeamFCC);
```
</div>

View File

@ -43,14 +43,14 @@ tests:
<div id='js-seed'>
```js
// the global variable
// The global variable
var fixedValue = 4;
// Add your code below this line
// Only change code below this line
function incrementer () {
// Add your code above this line
// Only change code above this line
}
var newValue = incrementer(fixedValue); // Should equal 5
@ -67,7 +67,7 @@ console.log(fixedValue); // Should print 4
<section id='solution'>
```js
// the global variable
// The global variable
var fixedValue = 4;
const incrementer = val => val + 1;

View File

@ -45,7 +45,7 @@ tests:
<div id='js-seed'>
```js
// the global variable
// The global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
// Change code below this line

View File

@ -49,10 +49,10 @@ tests:
```js
function nonMutatingSplice(cities) {
// Add your code below this line
// Only change code below this line
return cities.splice(3);
// Add your code above this line
// Only change code above this line
}
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
@ -69,9 +69,9 @@ nonMutatingSplice(inputCities);
```js
function nonMutatingSplice(cities) {
// Add your code below this line
// Only change code below this line
return cities.slice(0,3);
// Add your code above this line
// Only change code above this line
}
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);

View File

@ -43,10 +43,10 @@ tests:
```js
var globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
nonMutatingSort(globalArray);
```
@ -63,9 +63,9 @@ nonMutatingSort(globalArray);
```js
var globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Add your code below this line
// Only change code below this line
return [].concat(arr).sort((a,b) => a-b);
// Add your code above this line
// Only change code above this line
}
nonMutatingSort(globalArray);
```

View File

@ -50,10 +50,10 @@ tests:
```js
function sliceArray(anim, beginSlice, endSlice) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
sliceArray(inputAnim, 1, 3);
@ -70,9 +70,9 @@ sliceArray(inputAnim, 1, 3);
```js
function sliceArray(anim, beginSlice, endSlice) {
// Add your code below this line
// Only change code below this line
return anim.slice(beginSlice, endSlice)
// Add your code above this line
// Only change code above this line
}
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
sliceArray(inputAnim, 1, 3);

View File

@ -65,10 +65,10 @@ tests:
```js
function alphabeticalOrder(arr) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```
@ -84,9 +84,9 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```js
function alphabeticalOrder(arr) {
// Add your code below this line
// Only change code below this line
return arr.sort();
// Add your code above this line
// Only change code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```

View File

@ -53,10 +53,10 @@ tests:
```js
function splitify(str) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
splitify("Hello World,I-am code");
```
@ -72,9 +72,9 @@ splitify("Hello World,I-am code");
```js
function splitify(str) {
// Add your code below this line
// Only change code below this line
return str.split(/\W/);
// Add your code above this line
// Only change code above this line
}
```

View File

@ -50,10 +50,10 @@ tests:
```js
function checkPositive(arr) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
@ -69,9 +69,9 @@ checkPositive([1, 2, 3, -4, 5]);
```js
function checkPositive(arr) {
// Add your code below this line
// Only change code below this line
return arr.every(num => num > 0);
// Add your code above this line
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```

View File

@ -54,7 +54,7 @@ tests:
<div id='js-seed'>
```js
// the global variable
// The global variable
var watchList = [
{
"Title": "Inception",
@ -168,11 +168,11 @@ var watchList = [
}
];
// Add your code below this line
// Only change code below this line
var filteredList;
// Add your code above this line
// Only change code above this line
console.log(filteredList);
```
@ -187,7 +187,7 @@ console.log(filteredList);
<section id='solution'>
```js
// the global variable
// The global variable
var watchList = [
{
"Title": "Inception",
@ -301,9 +301,9 @@ var watchList = [
}
];
// Add your code below this line
// Only change code below this line
let filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) );
// Add your code above this line
// Only change code above this line
```
</section>

View File

@ -57,7 +57,7 @@ tests:
<div id='js-seed'>
```js
// the global variable
// The global variable
var watchList = [
{
"Title": "Inception",
@ -171,14 +171,14 @@ var watchList = [
}
];
// Add your code below this line
// Only change code below this line
var ratings = [];
for(var i=0; i < watchList.length; i++){
ratings.push({title: watchList[i]["Title"], rating: watchList[i]["imdbRating"]});
}
// Add your code above this line
// Only change code above this line
console.log(JSON.stringify(ratings));
```
@ -200,7 +200,7 @@ const removeJSComments = str => str.replace(/\/\*[\s\S]*?\*\/|\/\/.*$/gm, '');
<section id='solution'>
```js
// the global variable
// The global variable
var watchList = [
{
"Title": "Inception",

View File

@ -79,7 +79,7 @@ tests:
<div id='js-seed'>
```js
// the global variable
// The global variable
var watchList = [
{
"Title": "Inception",
@ -194,11 +194,11 @@ var watchList = [
];
function getRating(watchList){
// Add your code below this line
// Only change code below this line
var averageRating;
// Add your code above this line
// Only change code above this line
return averageRating;
}
console.log(getRating(watchList));
@ -214,7 +214,7 @@ console.log(getRating(watchList));
<section id='solution'>
```js
// the global variable
// The global variable
var watchList = [
{
"Title": "Inception",

View File

@ -50,10 +50,10 @@ tests:
```js
function checkPositive(arr) {
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
@ -69,9 +69,9 @@ checkPositive([1, 2, 3, -4, 5]);
```js
function checkPositive(arr) {
// Add your code below this line
// Only change code below this line
return arr.some(elem => elem > 0);
// Add your code above this line
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```

View File

@ -74,17 +74,14 @@ Animal.prototype.eat = function() { console.log("nom nom nom"); };
function Dog() { }
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
beagle.bark(); // Should print "Woof!"
```
</div>

View File

@ -75,7 +75,7 @@ function Dog(name) {
}
Dog.prototype = {
// Add your code below this line
// Only change code below this line
};
```

View File

@ -81,13 +81,10 @@ Animal.prototype = {
}
};
// Add your code below this line
// Only change code below this line
let duck; // Change this line
let beagle; // Change this line
duck.eat(); // Should print "nom nom nom"
beagle.eat(); // Should print "nom nom nom"
```
</div>

View File

@ -77,7 +77,7 @@ let beagle = new Dog("Snoopy");
let ownProps = [];
let prototypeProps = [];
// Add your code below this line
// Only change code below this line

View File

@ -82,11 +82,11 @@ function Penguin() { }
Penguin.prototype = Object.create(Bird.prototype);
Penguin.prototype.constructor = Penguin;
// Add your code below this line
// Only change code below this line
// Add your code above this line
// Only change code above this line
let penguin = new Penguin();
console.log(penguin.fly());

View File

@ -62,7 +62,7 @@ function Dog() { }
Bird.prototype = Object.create(Animal.prototype);
Dog.prototype = Object.create(Animal.prototype);
// Add your code below this line
// Only change code below this line

View File

@ -58,11 +58,11 @@ Animal.prototype = {
function Dog() { }
// Add your code below this line
// Only change code below this line
let beagle = new Dog();
beagle.eat(); // Should print "nom nom nom"
```
</div>

View File

@ -71,7 +71,7 @@ function Bird(name) {
let canary = new Bird("Tweety");
let ownProps = [];
// Add your code below this line
// Only change code below this line

View File

@ -64,7 +64,7 @@ function Dog(name) {
this.name = name;
}
// Add your code below this line
// Only change code below this line
function joinDogFraternity(candidate) {
}

View File

@ -55,7 +55,7 @@ function Dog(name) {
let beagle = new Dog("Snoopy");
// Add your code below this line
// Only change code below this line
```

View File

@ -68,7 +68,7 @@ function Dog() {
this.color = "brown";
this.numLegs = 4;
}
// Add your code below this line
// Only change code below this line
```

View File

@ -82,7 +82,7 @@ let boat = {
type: "race-boat"
};
// Add your code below this line
// Only change code below this line

View File

@ -50,7 +50,7 @@ let dog = {
name: "Spot",
numLegs: 4
};
// Add your code below this line
// Only change code below this line
```

View File

@ -60,7 +60,7 @@ function Dog(name) {
// Add your code above this line
// Only change code above this line
let beagle = new Dog("Snoopy");
```

View File

@ -64,7 +64,7 @@ function House(numBedrooms) {
this.numBedrooms = numBedrooms;
}
// Add your code below this line
// Only change code below this line

View File

@ -64,13 +64,8 @@ tests:
<div id='js-seed'>
```js
// example crowd gathering
let crowd = 'P1P2P3P4P5P6CCCP7P8P9';
let reCriminals = /./; // Change this line
let matchedCriminals = crowd.match(reCriminals);
console.log(matchedCriminals);
```
</div>
@ -83,13 +78,7 @@ console.log(matchedCriminals);
<section id='solution'>
```js
// example crowd gathering
let crowd = 'P1P2P3P4P5P6CCCP7P8P9';
let reCriminals = /C+/; // Change this line
let matchedCriminals = crowd.match(reCriminals);
```
</section>