# Write Higher Order Arrow Functions_2

Write Higher Order Arrow Functions_2
0
#1

Tell us what’s happening:
I am getting undefined values for all the elements in the new array produced by the MAP function, and I don’t know why. Thanks.

``````
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.map(e => {if(e>0 && Number.isInteger(e)){Math.pow(e,2)}});
// change code above this line
return squaredIntegers;

};
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
``````

OUTPUT:

``````[ undefined,
undefined,
undefined,
undefined,
undefined,
undefined,
undefined ]
``````

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

0 Likes

#2

That is because you are not returning any values in the map method’s callback function. Without an explicit/implicit return, a function will return undefined.

Below I put in line returns in your code, but did not modify the actual code written. Now, it should be easier for you to see you are not returning any values inside the callback function.

``````  const squaredIntegers = arr.map(e => {
if(e>0 && Number.isInteger(e)){
Math.pow(e,2)
}
});
``````
1 Like

#3

Thanks. I actually used the following because when I returned the Math.pow(e, 2) I outputted the correct values along with undefined values for the non integer inputs.

`````` const squaredIntegers = arr.filter(e1 => e1>0 && Number.isInteger(e1)).map(e2 => Math.pow(e2,2));
``````

This passed the assignment.

0 Likes