Conflicting results compared to the question

Tell us what’s happening:

I don’t know what the issue is with my code. I was asked to return positive
integers, and square them of which I did. However, when I ran the test. I failed,
one of the passing criteria showed an array with over 4 positive integers and
to pass, I am required to return 3.

I don’t know what I am missing in the question, may you please assist?

  **Your code so far**

function squareList(arr){

  let arr2 =  arr.filter(item => item > 0)
  .map(item => parseInt(item))
  .map(item => item * item)


  return arr2;
};

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

//squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2]) should return [16, 1764, 36].
  **Your browser information:**

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

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

Link to the challenge:

This converts a number into an integer. I don’t think that’s what you want.

It is what I intended to do. The question said, to return integers, since the array contained some decimal numbers within it.

The instructions said to only use the integers, not turn everything into an integer. Easy to mix up, but it makes a big difference!

Thank you for clarifying.

1 Like

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