It Won't Let Me Pass

Tell us what’s happening:
Just couldn’t pass the test for the follow rule.

Appreciated if anyone could point out the issue.

Thanks.

The rule that failed:
map , filter , or reduce should be used.

My code so far:


const squareList = (arr) => {
// Only change code below this line
return arr
  .filter((e)=> { return Number.isInteger(e) && e > 0 } )
  .map(v => v*v)
;
// Only change code above this line
};

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

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36.

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

Link to the challenge:

For some reason, if I put that filter on the same line as the return arr, it passes, something like:

return arr.filter((e)=> // ...

The map seems to be fine where it is.

Why? I don’t know. It doesn’t matter for JS, but I guess it does for the test that was written for this. To me, the way you wrote it is easier to read. (With the exception of the semicolon after the map being on the next line.)

Ah… Interesting… I spent 20 minutes trying to figure it out.

Thanks Kevin!

P.S. The position of the semicolon is just my habit to match the indentation. Much like IF and ENDIF or the curly braces.

I suspect that if you ever work in a company and start doing that, you’ll come out after work to find your tires slashed.

Once you get to the point that you are doing local development, I’d recommend using a linter to catch things like that and enforcing a “standard” format, like airbnb. It just becomes a habit and it will make it much easier to get along with other developers.

1 Like