# Write Higher Order Arrow Functions j

Tell us what’s happening:

i dont understand this lesson and what is the function of the filter

``````
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((num) => Number.isInteger(num));

squaredIntegers = squaredIntegers.map((square) => square*square);
// change code above this line
return squaredIntegers;
};
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
``````

User Agent is: `Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/65.0.3325.181 Chrome/65.0.3325.181 Safari/537.36`.

The filter method allows you to create a new array with all elements that pass the test implemented by a supplied function. If the test returns true, then the element is kept in the new array. If it is false, the element is not kept in the new array. In your code above, the filter is returning the evaluation of Number.isInteger on each element in arr. Only integers will be kept in the new array which gets assigned to squaredIntegers.

For example, the following:

``````const arr = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];

const squaredIntegers = arr.filter((num) => Number.isInteger(num));
console.log(squaredIntegers); // displays [ 4, 42, 6 ]
``````

is similar to:

``````const arr = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];

const newArr = [];
for (let i = 0; i < arr.length; i++) {
if (Number.isInteger(arr[i])) {
newArr.push(arr[i]);
}
}
console.log(newArr); // displays [ 4, 42, 6 ]
``````
1 Like