map()
, filter()
, and reduce()
, that take other functions as arguments for processing collections of data.
Read the following code:
FBPosts.filter(function(post) {We have written this with
return post.thumbnail !== null && post.shares > 100 && post.likes > 500;
})
filter()
to at least make it somewhat readable. Now compare it to the following code which uses arrow function syntax instead:
FBPosts.filter((post) => post.thumbnail !== null && post.shares > 100 && post.likes > 500)This code is more succinct and accomplishes the same task with fewer lines of code.
realNumberArray
and store the new array in the variable squaredIntegers
.
squaredIntegers
should be a constant variable (by using const
).
testString: 'getUserInput => assert(getUserInput(''index'').match(/const\s+squaredIntegers/g), ''squaredIntegers
should be a constant variable (by using const
).'');'
- text: squaredIntegers
should be an array
testString: 'assert(Array.isArray(squaredIntegers), ''squaredIntegers
should be an array
'');'
- text: 'squaredIntegers
should be [16, 1764, 36]
'
testString: 'assert.deepStrictEqual(squaredIntegers, [16, 1764, 36], ''squaredIntegers
should be [16, 1764, 36]
'');'
- text: function
keyword was not used.
testString: 'getUserInput => assert(!getUserInput(''index'').match(/function/g), ''function
keyword was not used.'');'
- text: loop should not be used
testString: 'getUserInput => assert(!getUserInput(''index'').match(/(for)|(while)/g), ''loop should not be used'');'
- text: 'map
, filter
, or reduce
should be used'
testString: 'getUserInput => assert(getUserInput(''index'').match(/map|filter|reduce/g), ''map
, filter
, or reduce
should be used'');'
```