You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rewrite the code so the global array bookList is not changed inside either function. The add function should add the given bookName to the end of the array passed to it and return a new array (list). The remove function should remove the given bookName from the array passed to it.
4
+
5
+
Note: Both functions should return an array, and any new parameters should be added before the bookName parameter.
6
+
7
+
- bookList should not change and still equal ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies",
8
+
"Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"].
9
+
- newBookList should equal ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies",
10
+
"Philosophiæ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae", "A Brief History of Time"].
11
+
- newerBookList should equal ["The Hound of the Baskervilles", "Philosophiæ Naturalis Principia Mathematica",
12
+
"Disquisitiones Arithmeticae"].
13
+
- newestBookList should equal ["The Hound of the Baskervilles", "Philosophiæ Naturalis Principia Mathematica",
14
+
"Disquisitiones Arithmeticae", "A Brief History of Time"].
15
+
*/
16
+
// The global variable
17
+
constbookList=[
18
+
"The Hound of the Baskervilles",
19
+
"On The Electrodynamics of Moving Bodies",
20
+
"Philosophiæ Naturalis Principia Mathematica",
21
+
"Disquisitiones Arithmeticae"
22
+
];
23
+
24
+
// Changed code below this line
25
+
functionadd(bookList,bookName){
26
+
letnewBookList=[...bookList];
27
+
28
+
newBookList.push(bookName);
29
+
30
+
returnnewBookList;
31
+
// Changed code above this line
32
+
}
33
+
34
+
// Changed code below this line
35
+
functionremove(bookList,bookName){
36
+
letnewBookList=[...bookList];
37
+
constbook_index=newBookList.indexOf(bookName);
38
+
if(book_index>=0){
39
+
40
+
newBookList.splice(book_index,1);
41
+
returnnewBookList;
42
+
43
+
// Changed code above this line
44
+
}
45
+
}
46
+
47
+
constnewBookList=add(bookList,'A Brief History of Time');
48
+
constnewerBookList=remove(bookList,'On The Electrodynamics of Moving Bodies');
49
+
constnewestBookList=remove(add(bookList,'A Brief History of Time'),'On The Electrodynamics of Moving Bodies');
The watchList array holds objects with information on several movies.
4
+
Use map on watchList to assign a new array of objects to the ratings variable.
5
+
Each movie in the new array should have only a title key with the name of the film, and a rating key with the IMDB rating.
6
+
The code in the editor currently uses a for loop to do this, so you should replace the loop functionality with your map expression.
7
+
8
+
- The watchList variable should not change.
9
+
- Your code should not use a for loop.
10
+
- Your code should use the map method.
11
+
- ratings should equal [
12
+
{"title": "Inception", "rating": "8.8"},
13
+
{"title": "Interstellar", "rating": "8.6"},
14
+
{"title": "The Dark Knight", "rating": "9.0"},
15
+
{"title": "Batman Begins", "rating": "8.3"},
16
+
{"title": "Avatar", "rating": "7.9"}].
17
+
*/
18
+
// The global variable
19
+
constwatchList=[
20
+
{
21
+
"Title": "Inception",
22
+
"Year": "2010",
23
+
"Rated": "PG-13",
24
+
"Released": "16 Jul 2010",
25
+
"Runtime": "148 min",
26
+
"Genre": "Action, Adventure, Crime",
27
+
"Director": "Christopher Nolan",
28
+
"Writer": "Christopher Nolan",
29
+
"Actors": "Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page, Tom Hardy",
30
+
"Plot": "A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.",
31
+
"Language": "English, Japanese, French",
32
+
"Country": "USA, UK",
33
+
"Awards": "Won 4 Oscars. Another 143 wins & 198 nominations.",
"Writer": "Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)",
73
+
"Actors": "Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine",
74
+
"Plot": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.",
75
+
"Language": "English, Mandarin",
76
+
"Country": "USA, UK",
77
+
"Awards": "Won 2 Oscars. Another 146 wins & 142 nominations.",
"Writer": "Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)",
95
+
"Actors": "Christian Bale, Michael Caine, Liam Neeson, Katie Holmes",
96
+
"Plot": "After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.",
97
+
"Language": "English, Urdu, Mandarin",
98
+
"Country": "USA, UK",
99
+
"Awards": "Nominated for 1 Oscar. Another 15 wins & 66 nominations.",
"Actors": "Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang",
118
+
"Plot": "A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.",
119
+
"Language": "English, Spanish",
120
+
"Country": "USA, UK",
121
+
"Awards": "Won 3 Oscars. Another 80 wins & 121 nominations.",
Use the filter Method to Extract Data from an Array:
3
+
The variable watchList holds an array of objects with information on several movies.
4
+
Use a combination of filter and map on watchList to assign a new array of objects with only title and rating keys.
5
+
The new array should only include objects where imdbRating is greater than or equal to 8.0.
6
+
Note that the rating values are saved as strings in the object and you may need to convert them into numbers to perform
7
+
mathematical operations on them.
8
+
9
+
- The watchList variable should not change.
10
+
- Your code should use the filter method.
11
+
- Your code should not use a for loop.
12
+
- filteredList should equal
13
+
[
14
+
{"title": "Inception", "rating": "8.8"},
15
+
{"title": "Interstellar", "rating": "8.6"},
16
+
{"title": "The Dark Knight", "rating": "9.0"},
17
+
{"title": "Batman Begins", "rating": "8.3"}
18
+
].
19
+
*/
20
+
// The global variable
21
+
constwatchList=[
22
+
{
23
+
"Title": "Inception",
24
+
"Year": "2010",
25
+
"Rated": "PG-13",
26
+
"Released": "16 Jul 2010",
27
+
"Runtime": "148 min",
28
+
"Genre": "Action, Adventure, Crime",
29
+
"Director": "Christopher Nolan",
30
+
"Writer": "Christopher Nolan",
31
+
"Actors": "Leonardo DiCaprio, Joseph Gordon-Levitt, Elliot Page, Tom Hardy",
32
+
"Plot": "A thief, who steals corporate secrets through use of dream-sharing technology, is given the inverse task of planting an idea into the mind of a CEO.",
33
+
"Language": "English, Japanese, French",
34
+
"Country": "USA, UK",
35
+
"Awards": "Won 4 Oscars. Another 143 wins & 198 nominations.",
"Writer": "Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)",
75
+
"Actors": "Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine",
76
+
"Plot": "When the menace known as the Joker wreaks havoc and chaos on the people of Gotham, the caped crusader must come to terms with one of the greatest psychological tests of his ability to fight injustice.",
77
+
"Language": "English, Mandarin",
78
+
"Country": "USA, UK",
79
+
"Awards": "Won 2 Oscars. Another 146 wins & 142 nominations.",
"Writer": "Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)",
97
+
"Actors": "Christian Bale, Michael Caine, Liam Neeson, Katie Holmes",
98
+
"Plot": "After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it.",
99
+
"Language": "English, Urdu, Mandarin",
100
+
"Country": "USA, UK",
101
+
"Awards": "Nominated for 1 Oscar. Another 15 wins & 66 nominations.",
"Actors": "Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang",
120
+
"Plot": "A paraplegic marine dispatched to the moon Pandora on a unique mission becomes torn between following his orders and protecting the world he feels is his home.",
121
+
"Language": "English, Spanish",
122
+
"Country": "USA, UK",
123
+
"Awards": "Won 3 Oscars. Another 80 wins & 121 nominations.",
0 commit comments