Don't know what is wrong with code

For some reason, I can’t see why my code isn’t working. Any help is appreciated!!!

const squareList = (arr) => {

return arr
.filter(num => num 0 & num % parseInt(num) == 0)
.map(num => Math.pow(num, 2));


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

Hey so lets take a loot at the callback you wrote for your Array.filter() call.

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

So logically I see that you want to check if the element in the array is larger than zero (AKA a positive number) AND the number is an integer. However:

  1. You forgot the > comparison operator in num 0
  2. the AND logical operator is && not &

As an aside, num%parseInt(num)==0 may not be the most efficient solution, as parseInt takes any input, convert it to string if not a string, then convert to int. But num%1==0 would be the same, since: num=1*num

1 Like

Hello, @MatchaCrisp! Sorry for taking so long to respond. I corrected my silly mistake and it worked. Thank you so much for your help! :pray: :grinning_face_with_smiling_eyes:


do num > 0. I believe you forgot that, can also do num % 2 ===1. This wiill filter for any elements that when divided by 2, leave remainder 1, which is both 5 and 3.


Once the topic has been marked as solved, there is no need to fill up the topic with additional replies. Thanks.

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