Test fails for weird reason

Tell us what’s happening:

Why don’t my code pass the test, I mean it fails at test 3 ( `map` , `filter` , or `reduce` should be used.), there is (filter or reduce) or is it must to use reduce and if, WHY?

``````
const squareList = (arr) => {
// Only change code below this line
var newArray = arr
.filter((i) => i > 0 && i % 1 === 0)
.map((item) => (item * item));

return newArray;
// Only change code above this line
};

const squaredIntegers = squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]);
console.log(squaredIntegers);

``````

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

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

Your code is fine - the test needs work.

``````var newArray = arr.filter((i) => i > 0 && i % 1 === 0)
.map((item) => (item * item));
``````

it will pass.

No, that doesn’t make sense - the test needs fixing.

1 Like

Never mind, I split the filter and map to separate lines

``````var newArray = arr
.filter((i) => i > 0 && i % 1 === 0)
.map((item) => (item * item));
``````

Like, following worked, still weird though.

`````` var newArray = arr.filter((i) => i > 0 && i % 1 === 0);
newArray = newArray.map((item) => (item * item));
``````

Thanks, but I split functions to sperate line and it passed the test.

1 Like

the tests don’t like this, try to put it in a single line

1 Like

Oh ok, that make sense thank you.