Write Higher Order Arrow Functions unable to square

Tell us what’s happening:
I’m able to pass all the test (not like it was hard) but I can’t figure out the method to solve for squared. I know filter takes the argument passed in (x) as in each iteration of a number in an array and sees if the return (=>) is true but i’m having trouble getting the x’s that pass the % 1 test to square

Your code so far

const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
  "use strict";
  // change code below this line
  const squaredIntegers = arr.filter((x) => (x % 1 === 0) * (x % 1 === 0));
  // change code above this line
  return squaredIntegers;
// test your code
const squaredIntegers = squareList(realNumberArray);

Your browser information:

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

Link to the challenge:

 const squaredIntegers = arr.filter((x) => (x % 1 === 0) * (x % 1 === 0));

This doesn’t make sense because in the filter callback, you’re doing Boolean * Boolean (true * true, true * false, false * true or false * false). This is not a thing.

You don’t need to do everything in one line. You don’t even need to do it all in one method (you could filter the array in one, then do something to the result of that, for example).

1 Like

I broke it up into 2 operations: first the filer() and then the map().

scroll below for solution.

const ints = arr.filter( n => n%1 === 0 && n>0 );
const squaredIntegers = ints.map(x => x*x);

squaredIntegers is what gets returned.