feat(curriculum): introduce let and const earlier (#43133)

* fix: move "Explore Differences Between..." to basic JS, update seed and tests

* fix: resequence "Declare String Variables"

* fix: move "Declare a Read-Only Variable..." to basic JS, update seed and tests

* fix: revert changes to non-English "Explore Differences Between..." test text

* fix: revert test strings, solutions, and seeds for non-English challenges

* fix: update "Declare String Variables" description

* fix: sync quotation marks in description and seed

* fix: modify note in "Declare a Read-Only..." challenge

* fix: update operator and compound assignment challenges

* fix: update string challenges

* fix: update array and array method challenges

* fix: update function and scope challenges, resequence slightly

* fix: "Word Blanks" solution

* fix: add spacing to seed

* fix: concatenating += challenge spacing

* fix: appending variables to strings spacing

* fix: find the length of a string spacing

* fix: removed instances of removedFromMyArray = 0

* fix: switch challenges

* fix: function argument and param spacing

* fix: update counting cards, object challenges, and record collection

* fix: finish rest of Basic JS section

* fix: introducing else statements solution

* fix: update spacing and wording

* fix: update wording for const challenge

* fix: update functional programming challenges

* fix: intermediate algorithms and cert challenges

* fix: revert some spacing and remove comments for fp challenge solutions

* feat: add notes with links to moved let and const challenges in first two es6 challenges

* fix: update es6 intro text

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/concatenating-strings-with-the-plus-equals-operator.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/finding-a-remainder-in-javascript.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/global-scope-and-functions.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/iterate-through-an-array-with-a-for-loop.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* Update curriculum/challenges/english/02-javascript-algorithms-and-data-structures/basic-javascript/declare-a-read-only-variable-with-the-const-keyword.md

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>

* fix: concatenating strings with plus operator seed

* fix: add comments back to Declare a Read-Only Variable... seed

* feat: add es6 to basic javascript redirect tests for let and const challenges

* fix: revert "Concatenating Strings with Plus Operator" seed

* fix: move test file to cypress/integration/learn/redirects, separate redirect tests

Co-authored-by: Shaun Hamilton <shauhami020@gmail.com>
This commit is contained in:
Kristofer Koishigawa
2021-10-26 01:55:58 +09:00
committed by GitHub
parent 71b555ab16
commit bcc9beff1f
134 changed files with 888 additions and 882 deletions

View File

@ -13,7 +13,7 @@ Functional programming is all about creating and using non-mutating functions.
The last challenge introduced the `concat` method as a way to combine arrays into a new one without mutating the original arrays. Compare `concat` to the `push` method. `push` adds an item to the end of the same array it is called on, which mutates that array. Here's an example:
```js
var arr = [1, 2, 3];
const arr = [1, 2, 3];
arr.push([4, 5, 6]);
```
@ -71,8 +71,9 @@ function nonMutatingPush(original, newItem) {
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
const first = [1, 2, 3];
const second = [4, 5];
nonMutatingPush(first, second);
```
@ -82,7 +83,6 @@ nonMutatingPush(first, second);
function nonMutatingPush(original, newItem) {
return original.concat(newItem);
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingPush(first, second);
const first = [1, 2, 3];
const second = [4, 5];
```

View File

@ -77,7 +77,6 @@ function urlSlug(title) {
# --solutions--
```js
// Only change code below this line
function urlSlug(title) {
return title.trim().split(/\s+/).join("-").toLowerCase();
}

View File

@ -57,9 +57,9 @@ Your `incrementer` function should return a value based on the global `fixedValu
```js
// The global variable
var fixedValue = 4;
let fixedValue = 4;
function incrementer () {
function incrementer() {
// Only change code below this line
@ -70,7 +70,7 @@ function incrementer () {
# --solutions--
```js
var fixedValue = 4
let fixedValue = 4
function incrementer() {
return fixedValue + 1

View File

@ -13,8 +13,8 @@ The `join` method is used to join the elements of an array together to create a
Here's an example:
```js
var arr = ["Hello", "World"];
var str = arr.join(" ");
const arr = ["Hello", "World"];
const str = arr.join(" ");
```
`str` would have a value of the string `Hello World`.
@ -76,6 +76,7 @@ function sentensify(str) {
// Only change code above this line
}
sentensify("May-the-force-be-with-you");
```
@ -83,8 +84,6 @@ sentensify("May-the-force-be-with-you");
```js
function sentensify(str) {
// Only change code below this line
return str.split(/\W/).join(' ');
// Only change code above this line
}
```

View File

@ -60,8 +60,9 @@ function nonMutatingConcat(original, attach) {
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
const first = [1, 2, 3];
const second = [4, 5];
nonMutatingConcat(first, second);
```
@ -69,11 +70,8 @@ nonMutatingConcat(first, second);
```js
function nonMutatingConcat(original, attach) {
// Only change code below this line
return original.concat(attach);
// Only change code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingConcat(first, second);
const first = [1, 2, 3];
const second = [4, 5];
```

View File

@ -38,17 +38,17 @@ assert(!code.match(/\.?[\s\S]*?map/g));
```js
// The global variable
var s = [23, 65, 98, 5];
const s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback) {
var newArray = [];
const newArray = [];
// Only change code below this line
// Only change code above this line
return newArray;
};
var new_s = s.myMap(function(item) {
const new_s = s.myMap(function(item) {
return item * 2;
});
```
@ -56,20 +56,17 @@ var new_s = s.myMap(function(item) {
# --solutions--
```js
// the global Array
var s = [23, 65, 98, 5];
const s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback) {
var newArray = [];
// Only change code below this line
for (var elem of this) {
const newArray = [];
for (const elem of this) {
newArray.push(callback(elem));
}
// Only change code above this line
return newArray;
};
var new_s = s.myMap(function(item) {
const new_s = s.myMap(function(item) {
return item * 2;
});
```

View File

@ -34,16 +34,16 @@ assert(!code.match(/\.?[\s\S]*?filter/g));
```js
// The global variable
var s = [23, 65, 98, 5];
const s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback) {
// Only change code below this line
var newArray = [];
const newArray = [];
// Only change code above this line
return newArray;
};
var new_s = s.myFilter(function(item) {
const new_s = s.myFilter(function(item) {
return item % 2 === 1;
});
```
@ -51,20 +51,17 @@ var new_s = s.myFilter(function(item) {
# --solutions--
```js
// the global Array
var s = [23, 65, 98, 5];
const s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback) {
var newArray = [];
// Only change code below this line
const newArray = [];
for (let i = 0; i < this.length; i++) {
if (callback(this[i])) newArray.push(this[i]);
}
// Only change code above this line
return newArray;
};
var new_s = s.myFilter(function(item) {
const new_s = s.myFilter(function(item) {
return item % 2 === 1;
});
```

View File

@ -35,7 +35,7 @@ curried(1)(2)
This is useful in your program if you can't supply all the arguments to a function at one time. You can save each function call into a variable, which will hold the returned function reference that takes the next argument when it's available. Here's an example using the curried function in the example above:
```js
var funcForY = curried(1);
const funcForY = curried(1);
console.log(funcForY(2)); // 3
```
@ -45,7 +45,8 @@ Similarly, <dfn>partial application</dfn> can be described as applying a few arg
function impartial(x, y, z) {
return x + y + z;
}
var partialFn = impartial.bind(this, 1, 2);
const partialFn = impartial.bind(this, 1, 2);
partialFn(10); // 13
```
@ -90,6 +91,7 @@ function add(x) {
// Only change code above this line
}
add(10)(20)(30);
```

View File

@ -53,10 +53,10 @@ assert(__newValue === 5);
```js
// The global variable
var fixedValue = 4;
let fixedValue = 4;
// Only change code below this line
function incrementer () {
function incrementer() {
// Only change code above this line
@ -66,15 +66,9 @@ function incrementer () {
# --solutions--
```js
// The global variable
var fixedValue = 4;
let fixedValue = 4;
// Only change code below this line
function incrementer (fixedValue) {
function incrementer(fixedValue) {
return fixedValue + 1;
// Only change code above this line
}
```

View File

@ -10,7 +10,7 @@ dashedName: refactor-global-variables-out-of-functions
So far, we have seen two distinct principles for functional programming:
1) Don't alter a variable or object - create new variables and objects and return them if need be from a function. Hint: using something like `var newArr = arrVar`, where `arrVar` is an array will simply create a reference to the existing variable and not a copy. So changing a value in `newArr` would change the value in `arrVar`.
1) Don't alter a variable or object - create new variables and objects and return them if need be from a function. Hint: using something like `const newArr = arrVar`, where `arrVar` is an array will simply create a reference to the existing variable and not a copy. So changing a value in `newArr` would change the value in `arrVar`.
2) Declare function parameters - any computation inside a function depends only on the arguments passed to the function, and not on any global object or variable.
@ -86,7 +86,7 @@ assert(
```js
// The global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
// Change code below this line
function add (bookName) {
@ -99,7 +99,7 @@ function add (bookName) {
// Change code below this line
function remove (bookName) {
var book_index = bookList.indexOf(bookName);
const book_index = bookList.indexOf(bookName);
if (book_index >= 0) {
bookList.splice(book_index, 1);
@ -109,9 +109,9 @@ function remove (bookName) {
}
}
var newBookList = add(bookList, 'A Brief History of Time');
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
const newBookList = add(bookList, 'A Brief History of Time');
const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
console.log(bookList);
```
@ -120,13 +120,13 @@ console.log(bookList);
```js
// The global variable
var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
const bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
function add (bookList, bookName) {
function add(bookList, bookName) {
return [...bookList, bookName];
}
function remove (bookList, bookName) {
function remove(bookList, bookName) {
const bookListCopy = [...bookList];
const bookNameIndex = bookList.indexOf(bookName);
if (bookNameIndex >= 0) {
@ -135,7 +135,7 @@ function remove (bookList, bookName) {
return bookListCopy;
}
var newBookList = add(bookList, 'A Brief History of Time');
var newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
var newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
const newBookList = add(bookList, 'A Brief History of Time');
const newerBookList = remove(bookList, 'On The Electrodynamics of Moving Bodies');
const newestBookList = remove(add(bookList, 'A Brief History of Time'), 'On The Electrodynamics of Moving Bodies');
```

View File

@ -11,7 +11,7 @@ dashedName: remove-elements-from-an-array-using-slice-instead-of-splice
A common pattern while working with arrays is when you want to remove items and keep the rest of the array. JavaScript offers the `splice` method for this, which takes arguments for the index of where to start removing items, then the number of items to remove. If the second argument is not provided, the default is to remove items through the end. However, the `splice` method mutates the original array it is called on. Here's an example:
```js
var cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
const cities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
cities.splice(3, 1);
```
@ -69,7 +69,8 @@ function nonMutatingSplice(cities) {
// Only change code above this line
}
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
```
@ -77,10 +78,7 @@ nonMutatingSplice(inputCities);
```js
function nonMutatingSplice(cities) {
// Only change code below this line
return cities.slice(0,3);
// Only change code above this line
}
var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
nonMutatingSplice(inputCities);
const inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
```

View File

@ -68,24 +68,23 @@ assert(JSON.stringify(nonMutatingSort([140000, 104, 99])) ===
## --seed-contents--
```js
var globalArray = [5, 6, 3, 2, 9];
const globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Only change code below this line
// Only change code above this line
}
nonMutatingSort(globalArray);
```
# --solutions--
```js
var globalArray = [5, 6, 3, 2, 9];
const globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Only change code below this line
return [].concat(arr).sort((a,b) => a-b);
// Only change code above this line
}
nonMutatingSort(globalArray);
```

View File

@ -13,8 +13,8 @@ The `slice` method returns a copy of certain elements of an array. It can take t
Here's an example:
```js
var arr = ["Cat", "Dog", "Tiger", "Zebra"];
var newArray = arr.slice(1, 3);
const arr = ["Cat", "Dog", "Tiger", "Zebra"];
const newArray = arr.slice(1, 3);
```
`newArray` would have the value `["Dog", "Tiger"]`.
@ -78,7 +78,8 @@ function sliceArray(anim, beginSlice, endSlice) {
// Only change code above this line
}
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
sliceArray(inputAnim, 1, 3);
```
@ -86,10 +87,7 @@ sliceArray(inputAnim, 1, 3);
```js
function sliceArray(anim, beginSlice, endSlice) {
// Only change code below this line
return anim.slice(beginSlice, endSlice)
// Only change code above this line
return anim.slice(beginSlice, endSlice);
}
var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
sliceArray(inputAnim, 1, 3);
const inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
```

View File

@ -18,6 +18,7 @@ function ascendingOrder(arr) {
return a - b;
});
}
ascendingOrder([1, 5, 2, 3, 4]);
```
@ -29,6 +30,7 @@ function reverseAlpha(arr) {
return a === b ? 0 : a < b ? 1 : -1;
});
}
reverseAlpha(['l', 'h', 'z', 'b', 's']);
```
@ -86,6 +88,7 @@ function alphabeticalOrder(arr) {
return arr
// Only change code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```
@ -93,9 +96,6 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```js
function alphabeticalOrder(arr) {
// Only change code below this line
return arr.sort();
// Only change code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```

View File

@ -13,11 +13,11 @@ The `split` method splits a string into an array of strings. It takes an argumen
Here are two examples that split one string by spaces, then another by digits using a regular expression:
```js
var str = "Hello World";
var bySpace = str.split(" ");
const str = "Hello World";
const bySpace = str.split(" ");
var otherString = "How9are7you2today";
var byDigits = otherString.split(/\d/);
const otherString = "How9are7you2today";
const byDigits = otherString.split(/\d/);
```
`bySpace` would have the value `["Hello", "World"]` and `byDigits` would have the value `["How", "are", "you", "today"]`.
@ -74,6 +74,7 @@ function splitify(str) {
// Only change code above this line
}
splitify("Hello World,I-am code");
```
@ -81,8 +82,6 @@ splitify("Hello World,I-am code");
```js
function splitify(str) {
// Only change code below this line
return str.split(/\W/);
// Only change code above this line
}
```

View File

@ -59,29 +59,29 @@ assert.deepEqual(finalTabs.tabs, [
```js
// tabs is an array of titles of each site open within the window
var Window = function(tabs) {
const Window = function(tabs) {
this.tabs = tabs; // We keep a record of the array inside the object
};
// When you join two windows into one window
Window.prototype.join = function (otherWindow) {
Window.prototype.join = function(otherWindow) {
this.tabs = this.tabs.concat(otherWindow.tabs);
return this;
};
// When you open a new tab at the end
Window.prototype.tabOpen = function (tab) {
Window.prototype.tabOpen = function(tab) {
this.tabs.push('new tab'); // Let's open a new tab for now
return this;
};
// When you close a tab
Window.prototype.tabClose = function (index) {
Window.prototype.tabClose = function(index) {
// Only change code below this line
var tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab
const tabsBeforeIndex = this.tabs.splice(0, index); // Get the tabs before the tab
const tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
@ -91,12 +91,12 @@ Window.prototype.tabClose = function (index) {
};
// Let's create three browser windows
var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
// Now perform the tab opening, closing, and other operations
var finalTabs = socialWindow
const finalTabs = socialWindow
.tabOpen() // Open a new tab for cat memes
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join
.join(workWindow.tabClose(1).tabOpen());
@ -106,40 +106,34 @@ console.log(finalTabs.tabs);
# --solutions--
```js
// tabs is an array of titles of each site open within the window
var Window = function(tabs) {
this.tabs = tabs; // We keep a record of the array inside the object
const Window = function(tabs) {
this.tabs = tabs;
};
// When you join two windows into one window
Window.prototype.join = function (otherWindow) {
Window.prototype.join = function(otherWindow) {
this.tabs = this.tabs.concat(otherWindow.tabs);
return this;
};
// When you open a new tab at the end
Window.prototype.tabOpen = function (tab) {
this.tabs.push('new tab'); // Let's open a new tab for now
Window.prototype.tabOpen = function(tab) {
this.tabs.push('new tab');
return this;
};
// When you close a tab
Window.prototype.tabClose = function (index) {
var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab
var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab
Window.prototype.tabClose = function(index) {
const tabsBeforeIndex = this.tabs.slice(0, index);
const tabsAfterIndex = this.tabs.slice(index + 1);
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex);
return this;
};
// Let's create three browser windows
var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); // Entertainment sites
const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']);
const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']);
const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']);
// Now perform the tab opening, closing, and other operations
var finalTabs = socialWindow
.tabOpen() // Open a new tab for cat memes
.join(videoWindow.tabClose(2)) // Close third tab in video window, and join
const finalTabs = socialWindow
.tabOpen()
.join(videoWindow.tabClose(2))
.join(workWindow.tabClose(1).tabOpen());
```

View File

@ -13,7 +13,8 @@ The `every` method works with arrays to check if *every* element passes a partic
For example, the following code would check if every element in the `numbers` array is less than 10:
```js
var numbers = [1, 5, 8, 0, 10, 11];
const numbers = [1, 5, 8, 0, 10, 11];
numbers.every(function(currentValue) {
return currentValue < 10;
});
@ -62,6 +63,7 @@ function checkPositive(arr) {
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]);
```js
function checkPositive(arr) {
// Only change code below this line
return arr.every(num => num > 0);
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```

View File

@ -55,7 +55,7 @@ Your code should not use a `for` loop.
assert(!code.match(/for\s*?\([\s\S]*?\)/g));
```
`filteredList` should equal `[{"title": "Inception","rating": "8.8"},{"title": "Interstellar","rating": "8.6"},{"title": "The Dark Knight","rating": "9.0"},{"title": "Batman Begins","rating": "8.3"}]`.
`filteredList` should equal `[{"title": "Inception", "rating": "8.8"}, {"title": "Interstellar", "rating": "8.6"}, {"title": "The Dark Knight", "rating": "9.0"}, {"title": "Batman Begins", "rating": "8.3"}]`.
```js
assert.deepEqual(filteredList, [
@ -72,7 +72,7 @@ assert.deepEqual(filteredList, [
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -187,7 +187,7 @@ var watchList = [
// Only change code below this line
var filteredList;
const filteredList = "";
// Only change code above this line
@ -197,8 +197,7 @@ console.log(filteredList);
# --solutions--
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -311,7 +310,5 @@ var watchList = [
}
];
// Only change code below this line
let filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) );
// Only change code above this line
const filteredList = watchList.filter(e => e.imdbRating >= 8).map( ({Title: title, imdbRating: rating}) => ({title, rating}) );
```

View File

@ -61,7 +61,7 @@ Your code should use the `map` method.
assert(code.match(/\.map/g));
```
`ratings` should equal `[{"title":"Inception","rating":"8.8"},{"title":"Interstellar","rating":"8.6"},{"title":"The Dark Knight","rating":"9.0"},{"title":"Batman Begins","rating":"8.3"},{"title":"Avatar","rating":"7.9"}]`.
`ratings` should equal `[{"title": "Inception", "rating": "8.8"}, {"title": "Interstellar", "rating": "8.6"}, {"title": "The Dark Knight", "rating": "9.0"},{"title": "Batman Begins", "rating": "8.3"}, {"title": "Avatar", "rating": "7.9"}]`.
```js
assert.deepEqual(ratings, [
@ -79,7 +79,7 @@ assert.deepEqual(ratings, [
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -194,9 +194,9 @@ var watchList = [
// 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"]});
const ratings = [];
for (let i = 0; i < watchList.length; i++) {
ratings.push({title: watchList[i]["Title"], rating: watchList[i]["imdbRating"]});
}
// Only change code above this line
@ -207,8 +207,7 @@ console.log(JSON.stringify(ratings));
# --solutions--
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -321,7 +320,7 @@ var watchList = [
}
];
var ratings = watchList.map(function(movie) {
const ratings = watchList.map(function(movie) {
return {
title: movie["Title"],
rating: movie["imdbRating"]

View File

@ -93,7 +93,7 @@ assert(getRating(watchList.filter((_, i) => i < 1 || i > 2)) === 8.55);
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -206,22 +206,22 @@ var watchList = [
}
];
function getRating(watchList){
function getRating(watchList) {
// Only change code below this line
var averageRating;
let averageRating;
// Only change code above this line
return averageRating;
}
console.log(getRating(watchList));
```
# --solutions--
```js
// The global variable
var watchList = [
const watchList = [
{
"Title": "Inception",
"Year": "2010",
@ -334,8 +334,8 @@ var watchList = [
}
];
function getRating(watchList){
var averageRating;
function getRating(watchList) {
let averageRating;
const rating = watchList
.filter(obj => obj.Director === "Christopher Nolan")
.map(obj => Number(obj.imdbRating));

View File

@ -13,7 +13,8 @@ The `some` method works with arrays to check if *any* element passes a particula
For example, the following code would check if any element in the `numbers` array is less than 10:
```js
var numbers = [10, 50, 8, 220, 110, 11];
const numbers = [10, 50, 8, 220, 110, 11];
numbers.some(function(currentValue) {
return currentValue < 10;
});
@ -62,6 +63,7 @@ function checkPositive(arr) {
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
@ -69,9 +71,6 @@ checkPositive([1, 2, 3, -4, 5]);
```js
function checkPositive(arr) {
// Only change code below this line
return arr.some(elem => elem > 0);
// Only change code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```