Write Higher Order Arrow Functions review

Tell us what’s happening:
Hi there,

Please I need a review on my code, as to why it does not pass the challenge.
Thanks very much!

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 = realNumberArray.filter((x) => Math.floor(x));
  realNumberArray.map((x) => x*x);
  // change code above this line
  return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions

Two things.

  1. This is returning the result of rounding down to the whole number. The tests require only integers, not fractions. Try to find the numbers that have a remainder of 0 (they will be fractions) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators

  2. squaredIntegers will be an array of all the filtered values. You are mapping over realNumberArray, which will include all the non-filtered items.

There are two main steps here:

Step 1: Get ahold of all the positive integers in the array passed in as a parameter (arr, NOT realNumberArray).

The positive integers in arr are 4, 42, and 6. You need to create a boolean expression in your filter function that will return true for those 3 numbers and false for all the others.

Step 2: Square the positive integers.

The result of Step 1 should be an array containing the 3 positive integers. You can then use your map function on THAT array of values (not on the original arr parameter).

You don’t need to use Math.floor instead your call back functions can return the following

const positiveIntegers = arr.filter(positive => {
    return positive > 0 && positive % 1 == 0;
  });
 const squaredInteger = positiveIntegers.map(square => {
    return square ** 2;
  });
  return squaredIntegers;
};