Write Higher Order Arrow Functions examples used in the problem

Tell us what’s happening:

For this problem can someone explain the examples, and what each function is doing?

Your code so far


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);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions

The example shows 2 functions:

FBPosts.filter(function(post) {
  return post.thumbnail !== null && post.shares > 100 && post.likes > 500;
})

FBPosts.filter((post) => post.thumbnail !== null && post.shares > 100 && post.likes > 500)

both of these filters do the same thing, the only difference is that the callback of the second filter is an arrow function, opposed to normal function.

FBPosts is an array of objects, filter runs the callback on each object of FBPosts and keeps it if the callback returns true, if the callback returns false it filters it out of the array. This doesn’t mutate the original array, it returns a new array.

So both statements return a new array, which is a filtered version of FBosts. They will only be in the new array if they satisfy all of the following:

  • Must have a thumbnail
  • Must have more than 100 shares
  • Must have more than 500 likes
1 Like