From 102c2b829a83d95cc18cc6026bc2dfaa981a95bd Mon Sep 17 00:00:00 2001
From: Randell Dawson <5313213+RandellDawson@users.noreply.github.com>
Date: Sun, 28 Apr 2019 02:01:14 -0700
Subject: [PATCH] fix: added 15 missing solutions (#35745)
---
...ay-using-concat-instead-of-push.english.md | 7 +-
...to-convert-strings-to-url-slugs.english.md | 11 +-
...-a-string-using-the-join-method.english.md | 6 +-
...-arrays-using-the-concat-method.english.md | 9 +-
.../implement-map-on-a-prototype.english.md | 18 ++-
...he-filter-method-on-a-prototype.english.md | 18 ++-
...obal-variables-out-of-functions.english.md | 30 ++++-
...y-using-slice-instead-of-splice.english.md | 8 +-
...out-changing-the-original-array.english.md | 8 +-
...an-array-using-the-slice-method.english.md | 8 +-
...betically-using-the-sort-method.english.md | 7 +-
...an-array-using-the-split-method.english.md | 6 +-
...nt-in-an-array-meets-a-criteria.english.md | 7 +-
...d-to-extract-data-from-an-array.english.md | 117 +++++++++++++++++-
...nts-in-an-array-meet-a-criteria.english.md | 7 +-
15 files changed, 252 insertions(+), 15 deletions(-)
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md
index b581f9ca81..4522780c9a 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/add-elements-to-the-end-of-an-array-using-concat-instead-of-push.english.md
@@ -64,6 +64,11 @@ nonMutatingPush(first, second);
```js
-// solution required
+function nonMutatingPush(original, newItem) {
+ return original.concat(newItem);
+}
+var first = [1, 2, 3];
+var second = [4, 5];
+nonMutatingPush(first, second);
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.english.md
index a963eff6a3..b5a31960df 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/apply-functional-programming-to-convert-strings-to-url-slugs.english.md
@@ -71,6 +71,15 @@ var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
```js
-// solution required
+// the global variable
+var globalTitle = "Winter Is Coming";
+
+// Add your 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"
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.english.md
index cc1cb61bef..2c6664fac1 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-an-array-into-a-string-using-the-join-method.english.md
@@ -63,6 +63,10 @@ sentensify("May-the-force-be-with-you");
```js
-// solution required
+function sentensify(str) {
+ // Add your code below this line
+ return str.split(/\W/).join(' ');
+ // Add your code above this line
+}
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.english.md
index a90ff5592b..7f21c38927 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/combine-two-arrays-using-the-concat-method.english.md
@@ -60,6 +60,13 @@ nonMutatingConcat(first, second);
```js
-// solution required
+function nonMutatingConcat(original, attach) {
+ // Add your code below this line
+ return original.concat(attach);
+ // Add your code above this line
+}
+var first = [1, 2, 3];
+var second = [4, 5];
+nonMutatingConcat(first, second);
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.english.md
index 0fdd0fc2b2..957d321215 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-map-on-a-prototype.english.md
@@ -64,6 +64,22 @@ var new_s = s.myMap(function(item){
```js
-// solution required
+// the global Array
+var s = [23, 65, 98, 5];
+
+Array.prototype.myMap = function(callback){
+ var newArray = [];
+ // Add your code below this line
+ for (var elem of this) {
+ newArray.push(callback(elem));
+ }
+ // Add your code above this line
+ return newArray;
+
+};
+
+var new_s = s.myMap(function(item){
+ return item * 2;
+});
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.english.md
index 7c7285ff8e..00076087dd 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/implement-the-filter-method-on-a-prototype.english.md
@@ -62,6 +62,22 @@ var new_s = s.myFilter(function(item){
```js
-// solution required
+// the global Array
+var s = [23, 65, 98, 5];
+
+Array.prototype.myFilter = function(callback){
+ var newArray = [];
+ // Add your code below this line
+ for (let i = 0;i
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.english.md
index 78b3f2c02c..181627915c 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/refactor-global-variables-out-of-functions.english.md
@@ -88,6 +88,34 @@ console.log(bookList);
```js
-// solution required
+// the global variable
+var bookList = ["The Hound of the Baskervilles", "On The Electrodynamics of Moving Bodies", "PhilosophiƦ Naturalis Principia Mathematica", "Disquisitiones Arithmeticae"];
+
+/* This function should add a book to the list and return the list */
+// New parameters should come before the bookName one
+
+// Add your code below this line
+function add (bookList, bookName) {
+ return [...bookList, bookName];
+ // Add your code above this line
+}
+
+/* This function should remove a book from the list and return the list */
+// New parameters should come before the bookName one
+
+// Add your code below this line
+function remove (bookList, bookName) {
+ const bookListCopy = [...bookList];
+ const bookNameIndex = bookList.indexOf(bookName);
+ if (bookNameIndex >= 0) {
+ bookListCopy.splice(bookNameIndex, 1);
+ }
+ return bookListCopy;
+ // Add your code above this line
+}
+
+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');
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.english.md
index ea8e778bbe..49c20c9fd3 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/remove-elements-from-an-array-using-slice-instead-of-splice.english.md
@@ -61,6 +61,12 @@ nonMutatingSplice(inputCities);
```js
-// solution required
+function nonMutatingSplice(cities) {
+ // Add your code below this line
+ return cities.slice(0,3);
+ // Add your code above this line
+}
+var inputCities = ["Chicago", "Delhi", "Islamabad", "London", "Berlin"];
+nonMutatingSplice(inputCities);
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.english.md
index 5a41f44f79..6436346d14 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-a-sorted-array-without-changing-the-original-array.english.md
@@ -58,6 +58,12 @@ nonMutatingSort(globalArray);
```js
-// solution required
+var globalArray = [5, 6, 3, 2, 9];
+function nonMutatingSort(arr) {
+ // Add your code below this line
+ return [].concat(arr).sort((a,b) => a-b);
+ // Add your code above this line
+}
+nonMutatingSort(globalArray);
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.english.md
index d41e96cbd5..1c2486c1cb 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/return-part-of-an-array-using-the-slice-method.english.md
@@ -62,6 +62,12 @@ sliceArray(inputAnim, 1, 3);
```js
-// solution required
+function sliceArray(anim, beginSlice, endSlice) {
+ // Add your code below this line
+ return anim.slice(beginSlice, endSlice)
+ // Add your code above this line
+}
+var inputAnim = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
+sliceArray(inputAnim, 1, 3);
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.english.md
index 84dc71d467..dcbc365fd7 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/sort-an-array-alphabetically-using-the-sort-method.english.md
@@ -64,6 +64,11 @@ alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```js
-// solution required
+function alphabeticalOrder(arr) {
+ // Add your code below this line
+ return arr.sort();
+ // Add your code above this line
+}
+alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.english.md
index 422abbebdc..1ff5901de1 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/split-a-string-into-an-array-using-the-split-method.english.md
@@ -60,6 +60,10 @@ splitify("Hello World,I-am code");
```js
-// solution required
+function splitify(str) {
+ // Add your code below this line
+ return str.split(/\W/);
+ // Add your code above this line
+}
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.english.md
index 7586c63c3c..5cd60121ec 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria.english.md
@@ -59,6 +59,11 @@ checkPositive([1, 2, 3, -4, 5]);
```js
-// solution required
+function checkPositive(arr) {
+ // Add your code below this line
+ return arr.every(num => num > 0);
+ // Add your code above this line
+}
+checkPositive([1, 2, 3, -4, 5]);
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.english.md
index 4c7e6afbad..8883e03f3f 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-filter-method-to-extract-data-from-an-array.english.md
@@ -172,6 +172,121 @@ console.log(filteredList);
```js
-// solution required
+// the global variable
+var watchList = [
+ {
+ "Title": "Inception",
+ "Year": "2010",
+ "Rated": "PG-13",
+ "Released": "16 Jul 2010",
+ "Runtime": "148 min",
+ "Genre": "Action, Adventure, Crime",
+ "Director": "Christopher Nolan",
+ "Writer": "Christopher Nolan",
+ "Actors": "Leonardo DiCaprio, Joseph Gordon-Levitt, Ellen Page, Tom Hardy",
+ "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.",
+ "Language": "English, Japanese, French",
+ "Country": "USA, UK",
+ "Awards": "Won 4 Oscars. Another 143 wins & 198 nominations.",
+ "Poster": "http://ia.media-imdb.com/images/M/MV5BMjAxMzY3NjcxNF5BMl5BanBnXkFtZTcwNTI5OTM0Mw@@._V1_SX300.jpg",
+ "Metascore": "74",
+ "imdbRating": "8.8",
+ "imdbVotes": "1,446,708",
+ "imdbID": "tt1375666",
+ "Type": "movie",
+ "Response": "True"
+ },
+ {
+ "Title": "Interstellar",
+ "Year": "2014",
+ "Rated": "PG-13",
+ "Released": "07 Nov 2014",
+ "Runtime": "169 min",
+ "Genre": "Adventure, Drama, Sci-Fi",
+ "Director": "Christopher Nolan",
+ "Writer": "Jonathan Nolan, Christopher Nolan",
+ "Actors": "Ellen Burstyn, Matthew McConaughey, Mackenzie Foy, John Lithgow",
+ "Plot": "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival.",
+ "Language": "English",
+ "Country": "USA, UK",
+ "Awards": "Won 1 Oscar. Another 39 wins & 132 nominations.",
+ "Poster": "http://ia.media-imdb.com/images/M/MV5BMjIxNTU4MzY4MF5BMl5BanBnXkFtZTgwMzM4ODI3MjE@._V1_SX300.jpg",
+ "Metascore": "74",
+ "imdbRating": "8.6",
+ "imdbVotes": "910,366",
+ "imdbID": "tt0816692",
+ "Type": "movie",
+ "Response": "True"
+ },
+ {
+ "Title": "The Dark Knight",
+ "Year": "2008",
+ "Rated": "PG-13",
+ "Released": "18 Jul 2008",
+ "Runtime": "152 min",
+ "Genre": "Action, Adventure, Crime",
+ "Director": "Christopher Nolan",
+ "Writer": "Jonathan Nolan (screenplay), Christopher Nolan (screenplay), Christopher Nolan (story), David S. Goyer (story), Bob Kane (characters)",
+ "Actors": "Christian Bale, Heath Ledger, Aaron Eckhart, Michael Caine",
+ "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.",
+ "Language": "English, Mandarin",
+ "Country": "USA, UK",
+ "Awards": "Won 2 Oscars. Another 146 wins & 142 nominations.",
+ "Poster": "http://ia.media-imdb.com/images/M/MV5BMTMxNTMwODM0NF5BMl5BanBnXkFtZTcwODAyMTk2Mw@@._V1_SX300.jpg",
+ "Metascore": "82",
+ "imdbRating": "9.0",
+ "imdbVotes": "1,652,832",
+ "imdbID": "tt0468569",
+ "Type": "movie",
+ "Response": "True"
+ },
+ {
+ "Title": "Batman Begins",
+ "Year": "2005",
+ "Rated": "PG-13",
+ "Released": "15 Jun 2005",
+ "Runtime": "140 min",
+ "Genre": "Action, Adventure",
+ "Director": "Christopher Nolan",
+ "Writer": "Bob Kane (characters), David S. Goyer (story), Christopher Nolan (screenplay), David S. Goyer (screenplay)",
+ "Actors": "Christian Bale, Michael Caine, Liam Neeson, Katie Holmes",
+ "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.",
+ "Language": "English, Urdu, Mandarin",
+ "Country": "USA, UK",
+ "Awards": "Nominated for 1 Oscar. Another 15 wins & 66 nominations.",
+ "Poster": "http://ia.media-imdb.com/images/M/MV5BNTM3OTc0MzM2OV5BMl5BanBnXkFtZTYwNzUwMTI3._V1_SX300.jpg",
+ "Metascore": "70",
+ "imdbRating": "8.3",
+ "imdbVotes": "972,584",
+ "imdbID": "tt0372784",
+ "Type": "movie",
+ "Response": "True"
+ },
+ {
+ "Title": "Avatar",
+ "Year": "2009",
+ "Rated": "PG-13",
+ "Released": "18 Dec 2009",
+ "Runtime": "162 min",
+ "Genre": "Action, Adventure, Fantasy",
+ "Director": "James Cameron",
+ "Writer": "James Cameron",
+ "Actors": "Sam Worthington, Zoe Saldana, Sigourney Weaver, Stephen Lang",
+ "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.",
+ "Language": "English, Spanish",
+ "Country": "USA, UK",
+ "Awards": "Won 3 Oscars. Another 80 wins & 121 nominations.",
+ "Poster": "http://ia.media-imdb.com/images/M/MV5BMTYwOTEwNjAzMl5BMl5BanBnXkFtZTcwODc5MTUwMw@@._V1_SX300.jpg",
+ "Metascore": "83",
+ "imdbRating": "7.9",
+ "imdbVotes": "876,575",
+ "imdbID": "tt0499549",
+ "Type": "movie",
+ "Response": "True"
+ }
+];
+// Add your 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
```
diff --git a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.english.md b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.english.md
index 04c8b8fdfa..7b0e0618b2 100644
--- a/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.english.md
+++ b/curriculum/challenges/english/02-javascript-algorithms-and-data-structures/functional-programming/use-the-some-method-to-check-that-any-elements-in-an-array-meet-a-criteria.english.md
@@ -59,6 +59,11 @@ checkPositive([1, 2, 3, -4, 5]);
```js
-// solution required
+function checkPositive(arr) {
+ // Add your code below this line
+ return arr.some(elem => elem > 0);
+ // Add your code above this line
+}
+checkPositive([1, 2, 3, -4, 5]);
```