# Functional Programming - Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem

Tell us what’s happening:
I don’t understand how to get only integers…
I need the hint spelled out in plain English to better understand what is happening…

.filter(num => num > 0 && num % parseInt(num) === 0)

…and number divided by a binary parseInt? strictly equal to zero???

what?

const squareList = arr => {
// Only change code below this line
return arr
.filter(arr => arr > 0)

.map(arr => Math.sqrt(arr))
// Only change code above this line
};

const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);

[ 2.1908902300206643, 2.23606797749979, 1.7320508075688772 ]

``````const squareList = arr => {
// Only change code below this line
return arr
.filter(arr => arr > 0)

.map(arr => Math.sqrt(arr))
// Only change code above this line
};

const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);
``````

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

Challenge: Functional Programming - Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem

You are filtering for positive numbers but you aren’t filtering for only integers.

Also, you want the square of each number, not the square root.

ok that helps my Math.sqrt line … Thank You

I replaced it with .map(arr => arr * 2)

That’s not squaring a number. That’s multiplying it by `2`. Squaring a number means multiplying it by itself.

ooops arr * arr
thanks

this little beauty is tripping me up … num % parseInt(num) === 0)

That is a condition to return only integers and not decimals. The modulo `%` means that the remainder of a division must be zero.

" The modulo operation (abbreviated “mod”, or “%” in many programming languages ) is the remainder when dividing. For example, “5 mod 3 = 2” which means 2 is the remainder when you divide 5 by 3."

The main purpose of using the parseInt function is to extract a number from a string . This turns the returned value to an actual number.

1 Like

THANK YOU DobarBREND! Excellent!

1 Like

Also, you can use the `Number.isInteger()` method I think is easier to read in the long run.

1 Like

awesome, I’m gonna try it…

Thank You

.filter(arr => arr > 0 && Number.isInterger(arr))

it says isInterger is not a fuction

Yes, but `Number.isInteger` is

I have Number in the code

.filter(arr => arr > 0 && Number.isInterger(arr))

I was trying to point out that you spelled it wrong. You have an extra `r` in there.

1 Like

oh man … thank you bbsmooth

I’m using my new laptop after I finish this certifiation

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.