--- id: 587d7b88367417b2b2512b45 title: Write Higher Order Arrow Functions challengeType: 1 videoUrl: '' localeTitle: 编写高阶箭头函数 --- ## Description
是时候我们看到处理数据时箭头功能有多强大了。 Arrow函数与高阶函数(例如map()filter()reduce()非常兼容,它们将其他函数作为处理数据集合的参数。阅读以下代码:
FBPosts.filter(function(post){
return post.thumbnail!== null && post.shares> 100 && post.likes> 500;
})
我们用filter()写了这个,至少使它有点可读。现在将它与以下使用箭头函数语法的代码进行比较:
FBPosts.filter((post)=> post.thumbnail!== null && post.shares> 100 && post.likes> 500)
此代码更简洁,使用更少的代码行完成相同的任务。
## Instructions
使用箭头函数语法计算数组realNumberArray中只有正整数(十进制数不是整数)的realNumberArray ,并将新数组存储在变量squaredIntegers
## Tests
```yml tests: - text: squaredIntegers应该是一个常量变量(通过使用const )。 testString: 'getUserInput => assert(getUserInput("index").match(/const\s+squaredIntegers/g), "squaredIntegers should be a constant variable (by using const).");' - text: squaredIntegers应该是一个array testString: 'assert(Array.isArray(squaredIntegers), "squaredIntegers should be an array");' - text: 'squaredIntegers应该是[16, 1764, 36] squaredIntegers [16, 1764, 36]' testString: 'assert.deepStrictEqual(squaredIntegers, [16, 1764, 36], "squaredIntegers should be [16, 1764, 36]");' - text: function关键字未使用。 testString: 'getUserInput => assert(!getUserInput("index").match(/function/g), "function keyword was not used.");' - text: 不应该使用循环 testString: 'getUserInput => assert(!getUserInput("index").match(/(for)|(while)/g), "loop should not be used");' - text: 应使用mapfilterreduce testString: 'getUserInput => assert(getUserInput("index").match(/map|filter|reduce/g), "map, filter, or reduce should be used");' ```
## Challenge Seed
```js const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]; const squareList = (arr) => { "use strict"; // change code below this line const squaredIntegers = arr; // change code above this line return squaredIntegers; }; // test your code const squaredIntegers = squareList(realNumberArray); console.log(squaredIntegers); ```
## Solution
```js // solution required ```