Write Higher Order Arrow Functions problem from fcc

Write Higher Order Arrow Functions problem from fcc


Tell us what’s happening:
the previous two problem before this i solved took me long time to understand inline functions,anonymous function,passing function as argument to other function but was able to understand them 80%.
i dont know how to proceed this problem

should i use for loop to iterate through elements of ‘arr’ and verify if they are positive integer ?
Your code so far

const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
  "use strict";
  // change code below this line
  const squaredIntegers = arr.filter(arr.);
  // change code above this line
  return squaredIntegers;
// test your code
const squaredIntegers = squareList(realNumberArray);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:


in your filter function, pass an anonymous function like you did before. Whatever parameter you will give, filter method will automatically only store items that pass your truthy test. So filter only integers first then map through the filtered array to square each value.


the parameter i have given to the anonymous function inside filter function is the same array ‘arr’?
ex: const squaredIntegers =arr.filter( (arr) => arr > 0 && arr % parseInt(arr) === 0 )
is it correct?


You can name it arr inside, but you should really name your arguments in such a way that they describe what they are. In this case you are calling filter on arr, which iterates through the elements of arr. Each element is a number, so a named like num or number would be a better argument.

const squaredIntegers =arr.filter( (num) => num > 0 && num % parseInt(num) === 0 )

Now you just need to use the map method on the filtered array you assigned to square integers. I would recommend renaming the variable squaredIntegers to what it really contains at this point. After the filter, it will only contain positive integers, so maybe rename it posIntArr or something like that. Then you can call join on the posIntArr and assign the result to squaredIntegers, because at the point, it really will only contain squared integers.