Write Higher Order Arrow Functions struggle

Write Higher Order Arrow Functions struggle
0

#1

Tell us what’s happening:
Well, I don’t knwo how to compute the square of only the positive integers. :frowning: Can somebody explain for me? Thanks in advance.

Your code so far


const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
  "use strict";
  // change code below this line
  const squaredIntegers = arr.filter((num) => num > 0 && parseInt(num) === 0)
  // 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) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

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


#2

You can use isInteger method to check if a number is integer or not.

I would run a map method before your filter and trim your array down to integers first.


#3

Thank you. I figured it out.