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,29 @@
---
title: Add Elements to the End of an Array Using concat Instead of push
localeTitle: 使用concat将元素添加到数组的末尾而不是push
---
## 使用concat将元素添加到数组的末尾而不是push
`push`方法将新元素添加到原始数组的末尾的地方, `concat`方法创建一个新数组,其中包含原始数组和新元素中的元素。使用`concat`时,原始数组保持不变。
#### 相关链接:
* [Array.prototype.concat](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat)
## 解
```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
localeTitle: 应用函数式编程将字符串转换为URL Slugs
---
## 应用函数式编程将字符串转换为URL Slugs
### 解
```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"
```
### 替代解决方案
```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,31 @@
---
title: Avoid Mutations and Side Effects Using Functional Programming
localeTitle: 使用功能编程避免突变和副作用
---
## 使用功能编程避免突变和副作用
### 问题解释
填写函数`incrementer`的代码,使其返回全局变量`fixedValue`的值增加1。 `fixedValue`不应该改变,不管功能多少次`incrememter`被调用。
### 提示1
`fixedValue`上使用增量运算符( `++` )将改变`fixedValue` ,这意味着它将不再引用它所分配的相同值。
### 解:
```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,35 @@
---
title: Combine an Array into a String Using the join Method
localeTitle: 使用join方法将Array组合成String
---
## 使用join方法将Array组合成String
### 问题解释
使用`sentensify`函数内的`join`方法(以及其他方法)从字符串`str`的单词创建一个句子。该函数应返回一个字符串。例如,“我喜欢星球大战”将被转换为“我喜欢星球大战”。对于此挑战,请勿使用`replace`方法。
#### 相关链接:
* [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)
* [常用表达](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)
### HINT1
您可能需要先将字符串转换为数组。
### 提示二
您可能需要使用正则表达式来拆分字符串。
### 解:
```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,24 @@
---
title: Combine Two Arrays Using the concat Method
localeTitle: 使用concat方法组合两个数组
---
## 使用concat方法组合两个数组
* concat方法用于连接两个或多个数组或字符串。
* 此方法不会改变现有数组,但会返回一个新数组。
## 解
```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,34 @@
---
title: Implement map on a Prototype
localeTitle: 在Prototype上实现地图
---
## 在Prototype上实现地图
要使用关键字解决此挑战,这是一个关键。
它将使我们能够访问我们调用myMap的对象。
从那里我们可以使用forEach或for循环向已经声明的空数组添加元素因为我们使用给定的回调方法修改每个元素。
```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;
});
```
### 有用的链接
[这个。 Javascript MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/this)
[这个。 Javascript W3Schools](https://www.w3schools.com/js/js_this.asp)

View File

@@ -0,0 +1,45 @@
---
title: Implement the filter Method on a Prototype
localeTitle: 在Prototype上实现过滤器方法
---
## 在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;
};
```
## 另一个用于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,11 @@
---
title: Functional Programming
localeTitle: 功能编程
---
## 功能编程
这是一个存根。 [帮助我们的社区扩展它](https://github.com/freecodecamp/guides/tree/master/src/pages/mathematics/quadratic-equations/index.md) 。
[这种快速风格指南有助于确保您的拉取请求被接受](https://github.com/freecodecamp/guides/blob/master/README.md) 。
#### 更多信息:

View File

@@ -0,0 +1,21 @@
---
title: Introduction to Currying and Partial Application
localeTitle: Currying和Partial Application简介
---
## Currying和Partial Application简介
### 解
```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,48 @@
---
title: Learn About Functional Programming
localeTitle: 了解功能编程
---
## 了解功能编程
函数有一个输入或参数`const myFunc = (input) => { ...code to execute... }` 。在这种情况下,输入是要创建多少杯茶。
### 方法
只需更改一行代码即可传递此问题。必须调用`getTea()`函数并将其存储在`tea4TeamFCC`变量中。确保通读`getTea()`函数并准确理解它的作用。该函数接受一个变量 - `numOfCups` 。首先制作一个`teaCups[]`数组并设置一个for循环来倒数传入函数的杯数。然后通过for循环的每次迭代将一杯新茶推入阵列。
从而产生一个阵列,其中包含最初传递给`getTea()`函数的大量茶杯。
### 解
```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,32 @@
---
title: Pass Arguments to Avoid External Dependence in a Function
localeTitle: 传递参数以避免函数中的外部依赖
---
## 传递参数以避免函数中的外部依赖
## 提示1
尝试将参数传递给函数并返回此参数的增加值。
**提前解决!**
## 基本代码解决方案
```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
```
### 方法
此代码将提供与上一个挑战相同的结果,只是这次我们将`fixedValue`作为参数传递给函数。

View File

@@ -0,0 +1,46 @@
---
title: Refactor Global Variables Out of Functions
localeTitle: 重构函数的全局变量
---
## 重构函数的全局变量
* 如果您在更改bookList时遇到问题请尝试在函数中使用该数组的副本。
* 这里有一些关于\[JavaScript如何处理函数参数\]的更多信息https://codeburst.io/javascript-passing-by-value-vs- reference-explanation-in-plain-english-8d00fd06a47c
## ![:beginner:](https://forum.freecodecamp.com/images/emoji/emoji_one/beginner.png?v=3 ":初学者:")基本代码解决方案
## 解决方案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.
}
}
```
## 解决方案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,24 @@
---
title: Remove Elements from an Array Using slice Instead of splice
localeTitle: 使用切片从阵列中删除元素而不是拼接
---
## 使用切片从阵列中删除元素而不是拼接
* splice和slice方法之间的区别在于slice方法不会改变原始数组而是返回一个新数组。
* slice方法需要2个参数才能使索引开始和结束切片结束是非包含的
* 如果您不想改变原始数组,可以使用切片方法。
## 解
```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
localeTitle: 返回排序数组而不更改原始数组
---
## 返回排序数组而不更改原始数组
### 方法
首先将作为参数的数组连接到新的空数组。然后使用上一个挑战中所见的`sort()`方法,并创建一个函数以按升序对新数组进行排序。
### 解
```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,34 @@
---
title: Return Part of an Array Using the slice Method
localeTitle: 使用切片方法返回数组的一部分
---
## 使用切片方法返回数组的一部分
### 问题解释
在给定提供的beginSlice和endSlice索引的情况下使用sliceArray函数中的slice方法返回anim数组的一部分。该函数应返回一个数组。
### 方法
只需编写一行代码即返回语句即可编写该函数。就像在给出的示例中一样,使用`beginSlice``endSlice`参数作为`slice()`方法的参数,将函数作为参数的数组`slice()` 。 记住`slice()`方法的结构:
```javascript
var arr = ["Cat", "Dog", "Tiger", "Zebra", "Ant"];
arr.slice([index-to-begin-slice] , [index-to-end-slice]);
```
### 解
```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);
```
#### 相关链接:
* [Array.prototype.slice](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice)

View File

@@ -0,0 +1,35 @@
---
title: Sort an Array Alphabetically using the sort Method
localeTitle: 使用sort方法按字母顺序对数组进行排序
---
## 使用sort方法按字母顺序对数组进行排序
### 方法
在给出的示例中,我们看到如何编写一个函数,该函数将以反向字母顺序返回一个新数组。
```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']
```
使用此逻辑,只需对函数进行反向工程,即可按字母顺序返回新数组。
### 解
```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,23 @@
---
title: Split a String into an Array Using the split Method
localeTitle: 使用split方法将字符串拆分为数组
---
## 使用split方法将字符串拆分为数组
### 方法
只需拆分字符串即可创建一个新的单词数组。
可以使用简单的正则表达式来实现此结果。
### 解
```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,51 @@
---
title: Understand Functional Programming Terminology
localeTitle: 理解功能编程术语
---
## 理解功能编程术语
### 方法
就像在上一次挑战中一样,您必须调用`getTea`方法并将其存储在变量中。只有这一次你有2个变量来存储2个单独的数据集。你会看到`getTea()`函数和以前一样只是现在它需要2个单独的参数。第一个参数是一个函数因此我们需要传入`prepareGreenTea()`函数或`prepareBlackTea()`函数,然后`numOfCups`第二个参数`numOfCups` ,它可以作为整数输入。
### 解
在本练习中,我们将更高阶函数的结果分配给变量。为此,我们使用回调函数作为参数调用函数。
## 暗示:
`javascript const basketOne = makeBasket(addFruit, 10)`
##解决方案:
\`\`\`的JavaScript
/ \*\*
* 一个很长的准备绿茶的过程。
* @return {string}一杯绿茶。 \*\* / const prepareGreenTea ==>'greenTea';
/ \*\*
* 获得一定数量的茶。
* @param {functionstring} prepareTea茶的准备功能。
* @param {number} numOfCups所需的茶杯数量。
* @return {Array 给定量的茶杯。 \*\* / const getTea =prepareTeanumOfCups=> { const teaCups = \[\];
forlet cups = 1; cups <= numOfCups; cups + = 1{ const teaCup = prepareTea; teaCups.push茶杯; }
回归茶杯; };
//在此行下方添加代码 const tea4GreenTeamFCC = getTeaprepareGreenTea27; // :) const tea4BlackTeamFCC = getTeaprepareBlackTea13; // :) //在此行上方添加代码
的console.log tea4GreenTeamFCC tea4BlackTeamFCC ;
\`\`\`
## 代码说明:
在上面的解决方案中,我们将函数`prepareGreenTea()``prepareBlackTea()`作为参数或回调函数传递给`getTea()`函数,这些函数被分配给我们的两个常量变量`tea4BlackTeamFCC``tea4GreenTeamFCC` 。 这样就不会改变全局变量,并且我们可以选择添加无限数量的`prepareTea()`方法的不同选项,因为它是一个传递给`getTea()`高阶函数的回调函数。

View File

@@ -0,0 +1,9 @@
---
title: Understand the Hazards of Using Imperative Code
localeTitle: 了解使用命令代码的危害
---
## 了解使用命令代码的危害
这是一个存根。 [帮助我们的社区扩展它](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) 。
[这种快速风格指南有助于确保您的拉取请求被接受](https://github.com/freecodecamp/guides/blob/master/README.md) 。

View File

@@ -0,0 +1,43 @@
---
title: Use the every Method to Check that Every Element in an Array Meets a Criteria
localeTitle: 使用every方法检查数组中的每个元素是否符合条件
---
## 使用every方法检查数组中的每个元素是否符合条件
### 问题说明:
使用`checkPositive`函数中的`every`方法检查`arr`每个元素是否为正数。该函数应返回一个布尔值。
#### 相关链接:
* [Array.prototype.every](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/every)
### 暗示
不要忘记`return`
## 解
```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]);
```
## 替代方案
```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,22 @@
---
title: Use the filter method to extract data from an array
localeTitle: 使用filter方法从数组中提取数据
---
## 使用filter方法从数组中提取数据
## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 "speech_balloon")提示1
这个挑战分两步解决。 首先Array.prototype.filter用于过滤数组因此它的元素具有imdbRating> 8.0。 之后可以使用Array.prototype.map将输出整形为所需的格式。
### 解
```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,27 @@
---
title: Use the map Method to Extract Data from an Array
localeTitle: 使用映射方法从数组中提取数据
---
## 使用映射方法从数组中提取数据
## ![:speech_balloon:](https://forum.freecodecamp.com/images/emoji/emoji_one/speech_balloon.png?v=3 "speech_balloon")提示1
array.prototype.map采用输入中的函数并返回一个数组。返回的数组包含由函数处理的元素。此函数将各个元素作为输入。
## 扰流警报!
![警告牌](//discourse-user-assets.s3.amazonaws.com/original/2X/2/2d6c412a50797771301e7ceabd554cef4edcd74d.gif)
**提前解决!**
## ![:rotating_light:](https://forum.freecodecamp.com/images/emoji/emoji_one/rotating_light.png?v=3 "rotating_light")中级代码解决方案:
```javascript
rating = watchList.map( (item) => ({"title":item["Title"], "rating":item["imdbRating"]}) );
```
###代码说明: 使用ES6表示法处理数组中的每个项目以提取标题和评级。 返回对象需要Parantheses。
#### 相关链接
* [箭头功能](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions)

View File

@@ -0,0 +1,130 @@
---
title: Use the reduce Method to Analyze Data
localeTitle: 使用reduce方法分析数据
---
## 使用reduce方法分析数据
```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,23 @@
---
title: Use the some Method to Check that Any Elements in an Array Meet a Criteria
localeTitle: 使用某些方法检查阵列中的任何元素是否符合条件
---
## 使用某些方法检查阵列中的任何元素是否符合条件
### 问题解释
使用checkPositive函数中的some方法检查arr中的任何元素是否为正数。 `checkPositive`函数应返回一个布尔值。
#### 相关链接:
* [Array.prototype.some](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/some)
### 解:
```javascript
function checkPositive(arr) {
return arr.some((elem) => elem > 0);
}
checkPositive([1, 2, 3, -4, 5]);
```