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:
@@ -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];
|
||||
|
@@ -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>
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -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];
|
||||
|
@@ -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;
|
||||
|
||||
};
|
||||
|
@@ -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;
|
||||
};
|
||||
|
||||
|
@@ -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);
|
||||
```
|
||||
|
@@ -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>
|
||||
|
@@ -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;
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
```
|
||||
|
@@ -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);
|
||||
|
@@ -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"]);
|
||||
```
|
||||
|
@@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
@@ -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]);
|
||||
```
|
||||
|
@@ -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>
|
||||
|
@@ -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",
|
||||
|
@@ -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",
|
||||
|
@@ -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]);
|
||||
```
|
||||
|
Reference in New Issue
Block a user