Using higher order function challenge

what are my suposed to do to the filtered values??
Tell us what’s happening:
Describe your issue in detail here.

  **Your code so far**

const squareList = arr => {
// Only change code below this line
return arr.filter(num => num > 0 && num % parseInt(num) === 0);

// 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 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36

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

Link to the challenge:

the instructions say

The function should return a new array containing the squares of only the positive integers

What part of that are you missing?

i have returned the positive numbers which are 5,3 with filter method

i mean i returned positive numbers 5,3 using filter method

The function should return a new array containing the squares…

I’m not seeing any squares. A square is a number multiplied by itself. 9 is 3 squared, for example.

i need help on returning new array containing squares
const squareList = arr => {
  // Only change code below this line
  return arr.filter(y => Number.isInteger(y) && y > 0);
  arr.map(y => y * y )
  
  // Only change code above this line
};

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

A return statement immediately stops your function. The map never happens.

so are you insinuating i erase the return statement??

i had to put the return statement on reduce.this is my output on console.log [ 9, 23.04, 25, 9, 10.240000000000002 ]

of which the squares of 5,3 are there,but am not passing the challenge

You need a return statement somewhere. But if you return before you square the numbers, then you’ll never square the numbers… That’s how return statements work.

The challenge is asking you to both remove certain elements and square the rest. You need to use the output from your filter and reduce to accomplish this.

thanks i got it at last

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