fix(guide): simplify directory structure

This commit is contained in:
Mrugesh Mohapatra
2018-10-16 21:26:13 +05:30
parent f989c28c52
commit da0df12ab7
35752 changed files with 0 additions and 317652 deletions

View File

@ -0,0 +1,26 @@
---
title: Add Elements to the End of an Array Using concat Instead of push
---
## Add Elements to the End of an Array Using concat Instead of push
Where the `push` method adds new element to the end of the orginal array, the `concat` method creates a new array containing the elements from the original array and the new element. The original array remains the same when using `concat`.
#### Relevant Links:
- [Array.prototype.concat()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
## Solution
```javascript
function nonMutatingPush(original, newItem) {
// Add your code below this line
return original.concat(newItem);
// Add your code above this line
}
var first = [1, 2, 3];
var second = [4, 5];
nonMutatingPush(first, second);
```

View File

@ -0,0 +1,39 @@
---
title: Apply Functional Programming to Convert Strings to URL Slugs
---
## Apply Functional Programming to Convert Strings to URL Slugs
### Solution
```javascript
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title.split(/\W/).filter((obj)=>{
return obj !=='';
}).join('-').toLowerCase();
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
```
### Alternative solution
```javascript
// the global variable
var globalTitle = "Winter Is Coming";
// Add your code below this line
function urlSlug(title) {
return title.toLowerCase().trim().split(/\s+/).join('-');
}
// Add your code above this line
var winterComing = urlSlug(globalTitle); // Should be "winter-is-coming"
```

View File

@ -0,0 +1,28 @@
---
title: Avoid Mutations and Side Effects Using Functional Programming
---
## Avoid Mutations and Side Effects Using Functional Programming
### Problem Explanation
Fill in the code for the function `incrementer` so it returns the value of the global variable `fixedValue` increased by one. `fixedValue` should not change, no matter how many times the function `incrememter` is called.
### Hint 1
Using the increment operator (`++`) on `fixedValue` will mutate `fixedValue`, meaning it will no longer reference the same value it was assigned with.
### Solution:
```javascript
// the global variable
var fixedValue = 4;
function incrementer () {
// Add your code below this line
return fixedValue + 1;
// Add your code above this line
}
var newValue = incrementer(); // Should equal 5
console.log(fixedValue); // Should print 4
```

View File

@ -0,0 +1,30 @@
---
title: Combine an Array into a String Using the join Method
---
## Combine an Array into a String Using the join Method
### Problem Explanation
Use the `join` method (among others) inside the `sentensify` function to make a sentence from the words in the string `str`. The function should return a string. For example, "I-like-Star-Wars" would be converted to "I like Star Wars". For this challenge, do not use the `replace` method.
#### Relevant Links:
- [Array.prototype.join()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join)
- [String.prototype.split()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split)
- [Regular Expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
### Hint1
You may need to convert the string to an array first.
### Hint2
You may need to use regular expression to split the string.
### Solution:
```javascript
function sentensify(str) {
// Add your code below this line
return str.split(/\W/).join(' ');
// Add your code above this line
}
sentensify("May-the-force-be-with-you");
```

View File

@ -0,0 +1,21 @@
---
title: Combine Two Arrays Using the concat Method
---
## Combine Two Arrays Using the concat Method
- The concat method is used to join two or more arrays or strings.
- This method does not mutate the existing arrays, but returns a new array.
## Solution
```javascript
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);
```

View File

@ -0,0 +1,33 @@
---
title: Implement map on a Prototype
---
## Implement map on a Prototype
To solve THIS challenge using the keyword this is a key.
It will give us access to the object we are calling myMap.
From there we can use the forEach or for loop to add elements to already declared empty array as we modify each element with the given callback method.
```javascript
// the global Array
var s = [23, 65, 98, 5];
Array.prototype.myMap = function(callback){
var newArray = [];
// Add your code below this line
this.forEach(a => newArray.push(callback(a)));
// Add your code above this line
return newArray;
};
var new_s = s.myMap(function(item){
return item * 2;
});
```
### Useful Links
[this. Javascript MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)<br/>
[this. Javascript W3Schools](https://www.w3schools.com/js/js_this.asp)

View File

@ -0,0 +1,47 @@
---
title: Implement the filter Method on a Prototype
---
## Implement the filter Method on a Prototype
```javascript
// the global Array
var s = [23, 65, 98, 5];
Array.prototype.myFilter = function(callback){
var newArray = [];
// Add your code below this line
this.forEach(function(x) {
if (callback(x) == true) {
newArray.push(x);
}
})
// Add your code above this line
return newArray;
};
```
## Another solution using for looop!
```javascript
Array.prototype.myFilter = function(callback){
var newArray = [];
// Add your code below this line
for (let i=0; i<this.length;i++){
if(callback(this[i])=== true ){
newArray.push(this[i]);
}
}
// Add your code above this line
return newArray;
};
var new_s = s.myFilter(function(item){
return item % 2 === 1;
});
```

View File

@ -0,0 +1,13 @@
---
title: Functional Programming
---
## Functional Programming
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/mathematics/quadratic-equations/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
#### More Information:
<!-- Please add any articles you think might be helpful to read before writing the article -->

View File

@ -0,0 +1,21 @@
---
title: Introduction to Currying and Partial Application
---
## Introduction to Currying and Partial Application
### Solution
```javascript
function add(x) {
// Add your code below this line
return function(y) {
return function(z) {
return x + y + z;
}
}
// Add your code above this line
}
add(10)(20)(30);
```

View File

@ -0,0 +1,47 @@
---
title: Learn About Functional Programming
---
## Learn About Functional Programming
A function has an input or a parameter ``` const myFunc = (input) => { ...code to execute... } ```. In this case the input is how many cups of tea to be created.
<br/>
### Method
Only one line of code must be changed to pass this challenege. The `getTea()` function must be called and stored in the `tea4TeamFCC` variable. Make sure to read through the `getTea()` function and understand exactly what it does. The function takes in one variable - `numOfCups`. A `teaCups[]` array is first made and a for loop is set up to count down the number of cups passed into the function. A new cup of tea is then pushed to the array through every iteration of the for loop.
Thus resulting in an array full of the amount of teacups originally passed into the `getTea()` function.
### Solution
```javascript
/**
* A long process to prepare tea.
* @return {string} A cup of tea.
**/
const prepareTea = () => 'greenTea';
/**
* Get given number of cups of tea.
* @param {number} numOfCups Number of required cups of tea.
* @return {Array<string>} Given amount of tea cups.
**/
const getTea = (numOfCups) => {
const teaCups = [];
for(let cups = 1; cups <= numOfCups; cups += 1) {
const teaCup = prepareTea();
teaCups.push(teaCup);
}
return teaCups;
};
// Add your code below this line
const tea4TeamFCC = getTea(40); // :(
// Add your code above this line
console.log(tea4TeamFCC);
```

View File

@ -0,0 +1,35 @@
---
title: Pass Arguments to Avoid External Dependence in a Function
---
## Pass Arguments to Avoid External Dependence in a Function
## Hint: 1
Try to pass argument to function and return increased value of this argument.
**Solution ahead!**
## Basic Code Solution:
```javascript
// the global variable
var fixedValue = 4;
// Add your code below this line
function incrementer (value) {
return value + 1;
// Add your code above this line
}
var newValue = incrementer(fixedValue); // Should equal 5
console.log(fixedValue); // Should print 4
```
### Method
This code will provide the same result as the last challenge, only this time we will pass the `fixedValue` into the function as a parameter.

View File

@ -0,0 +1,41 @@
---
title: Refactor Global Variables Out of Functions
---
## Refactor Global Variables Out of Functions
- If you're having trouble with changing bookList, try using a copy of the array in your functions.
- Here's some more information about [how JavaScript handles function arguments](https://codeburst.io/javascript-passing-by-value-vs- reference-explained-in-plain-english-8d00fd06a47c).
## ![:beginner:](https://forum.freecodecamp.com/images/emoji/emoji_one/beginner.png?v=3 ":beginner:") Basic Code Solution:
## Solution 1
```javascript
function add (arr, bookName) {
let newArr = [...arr]; // Copy the bookList array to a new array.
newArr.push(bookName); // Add bookName parameter to the end of the new array.
return newArr; // Return the new array.
}
function remove (arr, bookName) {
let newArr = [...arr]; // Copy the bookList array to a new array.
if (newArr.indexOf(bookName) >= 0) { // Check whether the bookName parameter is in new array.
/.
newArr.splice(newArr.indexOf(bookName), 1); // Remove the given paramater from the new array.
return newArr; // Return the new array.
}
}
```
## Solution 2
```javascript
function add (list,bookName) {
return [...list, bookName];
}
function remove (list,bookName) {
if (list.indexOf(bookName) >= 0) {
return list.filter((item) => item !== bookName);
}
}
```

View File

@ -0,0 +1,21 @@
---
title: Remove Elements from an Array Using slice Instead of splice
---
## Remove Elements from an Array Using slice Instead of splice
- The difference between splice and slice method is that the slice method does not mutate the original array, but returns a new one.
- The slice method takes 2 two arguments for the indices to begin and end the slice (the end is non-inclusive).
- If you do not want to mutate the original array, you can use the slice method.
## Solution
```javascript
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);
```

View File

@ -0,0 +1,24 @@
---
title: Return a Sorted Array Without Changing the Original Array
---
## Return a Sorted Array Without Changing the Original Array
### Method
Firstly concatenate the array taken in as a parameter to a new empty array. Then Use the `sort()` method as seen in the last challenge and create a function to sort the new array in ascending order.
### Solution
```javascript
var globalArray = [5, 6, 3, 2, 9];
function nonMutatingSort(arr) {
// Add your code below this line
return [].concat(arr).sort(function(a, b) {
return a - b;
});
// Add your code above this line
}
nonMutatingSort(globalArray);
```

View File

@ -0,0 +1,35 @@
---
title: Return Part of an Array Using the slice Method
---
## Return Part of an Array Using the slice Method
### Problem Explanation
Use the slice method in the sliceArray function to return part of the anim array given the provided beginSlice and endSlice indices. The function should return an array.
### Method
The function can be written by simply writing one line of code - a return statement. Just like in the example given, slice the array which the function takes as a parameter using the `beginSlice` and `endSlice` parameters as parameters for the `slice()` method.
Remember the structure of the `slice()` method:
```javascript
var arr = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
arr.slice([index-to-begin-slice] , [index-to-end-slice]);
```
### Solution
```javascript
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);
```
#### Relevant Links:
- [Array.prototype.slice()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)

View File

@ -0,0 +1,37 @@
---
title: Sort an Array Alphabetically using the sort Method
---
## Sort an Array Alphabetically using the sort Method
### Method
In the example given we see how to write a function which will return a new array in reverse alphabetical order.
```javascript
function reverseAlpha(arr) {
return arr.sort(function(a, b) {
return a < b;
});
}
reverseAlpha(['l', 'h', 'z', 'b', 's']);
// Returns ['z', 's', 'l', 'h', 'b']
```
Using this logic, simply reverse engineer the function to return a new array in alphabetical order.
### Solution
```javascript
function alphabeticalOrder(arr) {
// Add your code below this line
return arr.sort(function(a,b) {
return a > b;
});
// Add your code above this line
}
alphabeticalOrder(["a", "d", "c", "a", "z", "g"]);
```

View File

@ -0,0 +1,18 @@
---
title: Split a String into an Array Using the split Method
---
## Split a String into an Array Using the split Method
### Method
Simply split the string to create a new array of words.
A simple regular expression can be used to achieve this result.
### Solution
```javascript
function splitify(str) {
// Add your code below this line
return str.split(/\W/);
// Add your code above this line
}
splitify("Hello World,I-am code");
```

View File

@ -0,0 +1,61 @@
---
title: Understand Functional Programming Terminology
---
## Understand Functional Programming Terminology
### Method
Just as in the last challenge, you must call the `getTea` method and store it in a variable. Only this time, you have 2 variables to store 2 seperate sets of data in. You will see that the `getTea()` function is the same as before, only now it takes in 2 seperate parameters. The first parameter is a function, so we will need to pass in either the `prepareGreenTea()` function or the `prepareBlackTea()` function, followed by the second parameter `numOfCups` which can be input as an integer.
### Solution
In this exercise we are assigning the result of a higher order function to variables. To do this we call a function with a callback function as a parameter.
## Hint:
```javascript
const basketOne = makeBasket(addFruit, 10)
```
## Solution:
```javascript
/**
* A long process to prepare green tea.
* @return {string} A cup of green tea.
**/
const prepareGreenTea = () => 'greenTea';
/**
* Get given number of cups of tea.
* @param {function():string} prepareTea The type of tea preparing function.
* @param {number} numOfCups Number of required cups of tea.
* @return {Array<string>} Given amount of tea cups.
**/
const getTea = (prepareTea, numOfCups) => {
const teaCups = [];
for(let cups = 1; cups <= numOfCups; cups += 1) {
const teaCup = prepareTea();
teaCups.push(teaCup);
}
return teaCups;
};
// Add your code below this line
const tea4GreenTeamFCC = getTea(prepareGreenTea,27); // :)
const tea4BlackTeamFCC = getTea(prepareBlackTea,13); // :)
// Add your code above this line
console.log(
tea4GreenTeamFCC,
tea4BlackTeamFCC
);
```
## Code explanation:
In the solution above we passed in the functions ``` prepareGreenTea() ``` and ``` prepareBlackTea() ``` as parameters or callback functions for the ``` getTea() ``` functions being assigned to our two constant variables ``` tea4BlackTeamFCC ```
and ``` tea4GreenTeamFCC ```.
This way no global variables are changed, and we have the option to add an unlimited number of different choices of ``` prepareTea() ``` methods since it is a callback function being passed to the higher order function of ``` getTea() ```.

View File

@ -0,0 +1,10 @@
---
title: Understand the Hazards of Using Imperative Code
---
## Understand the Hazards of Using Imperative Code
This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/javascript-algorithms-and-data-structures/functional-programming/understand-the-hazards-of-using-imperative-code/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>.
<a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>.
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->

View File

@ -0,0 +1,44 @@
---
title: Use the every Method to Check that Every Element in an Array Meets a Criteria
---
## Use the every Method to Check that Every Element in an Array Meets a Criteria
<!-- This is a stub. <a href='https://github.com/freecodecamp/guides/tree/master/src/pages/certifications/javascript-algorithms-and-data-structures/functional-programming/use-the-every-method-to-check-that-every-element-in-an-array-meets-a-criteria/index.md' target='_blank' rel='nofollow'>Help our community expand it</a>. -->
<!-- <a href='https://github.com/freecodecamp/guides/blob/master/README.md' target='_blank' rel='nofollow'>This quick style guide will help ensure your pull request gets accepted</a>. -->
<!-- The article goes here, in GitHub-flavored Markdown. Feel free to add YouTube videos, images, and CodePen/JSBin embeds -->
### Problem Explanation:
Use the `every` method inside the `checkPositive` function to check if every element in `arr` is positive. The function should return a Boolean value.
#### Relevant Links:
- [Array.prototype.every()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
### Hint
Don't forget `return`.
## Solution
```javascript
function checkPositive(arr) {
// Add your code below this line
return arr.every(val => val > 0);
// Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```
## Alternative Solution
```javascript
function checkPositive(arr) {
// Add your code below this line
return arr.every(function(value) {
return value > 0;
});
// Add your code above this line
}
checkPositive([1, 2, 3, -4, 5]);
```

View File

@ -0,0 +1,23 @@
---
title: Use the filter method to extract data from an array
---
## Use the filter method to extract data from an array
## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 ":speech_balloon:") Hint: 1
This challange is solved in 2 steps.
First, Array.prototype.filter is used to filter the array so it's left with elements that have imdbRating > 8.0.
After that, Array.prototype.map can be used to shape the output to the desired format.
### Solution
```javascript
// Add your code below this line
var filteredList = watchList.map(function(e) {
return {title: e["Title"], rating: e["imdbRating"]}
}).filter((e) => e.rating >= 8);
console.log(filteredList);
```

View File

@ -0,0 +1,25 @@
---
title: Use the map Method to Extract Data from an Array
---
## Use the map Method to Extract Data from an Array
## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 ":speech_balloon:") Hint: 1
array.prototype.map takes a function as in input and returns an array. The returned array includes elements that is processed by the function. This function takes individual elements as input.
## Spoiler Alert!
![warning sign](//discourse-user-assets.s3.amazonaws.com/original/2X/2/2d6c412a50797771301e7ceabd554cef4edcd74d.gif)
**Solution ahead!**
## ![:rotating_light:](https://forum.freecodecamp.com/images/emoji/emoji_one/rotating_light.png?v=3 ":rotating_light:") Intermediate Code Solution:
```javascript
rating = watchList.map( (item) => ({"title":item["Title"], "rating":item["imdbRating"]}) );
```
### Code Explanation:
Using ES6 notation, each item in array is processed to extract title and rating.
Parantheses are needed to return an object.
#### Relevant Links
* <a href='https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions' target='_blank' rel='nofollow'>Arrow Functions</a>

View File

@ -0,0 +1,130 @@
---
title: Use the reduce Method to Analyze Data
---
## Use the reduce Method to Analyze Data
```javascript
// 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
var averageRating = watchList.filter(x => x.Director === "Christopher Nolan").map(x => Number(x.imdbRating)).reduce((x1, x2) => x1 + x2) / watchList.filter(x => x.Director === "Christopher Nolan").length;
// Add your code above this line
console.log(averageRating);
```

View File

@ -0,0 +1,20 @@
---
title: Use the some Method to Check that Any Elements in an Array Meet a Criteria
---
## Use the some Method to Check that Any Elements in an Array Meet a Criteria
### Problem Explanation
Use the some method inside the checkPositive function to check if any element in arr is positive. The `checkPositive` function should return a Boolean value.
#### Relevant Links:
- [Array.prototype.some()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
### Solution:
```javascript
function checkPositive(arr) {
return arr.some((elem) => elem > 0);
}
checkPositive([1, 2, 3, -4, 5]);
```