Write Higher Order Arrow Functions -FCC

Write Higher Order Arrow Functions -FCC
0.0 0

#1

Tell us what’s happening:
I have ended up here solving this, can anyone help me, please?

My 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((arr) => arr > 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 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36.

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


#2

Hey Guys, I got the solution. Use Number.isInteger() method to filter out the integers, here is the solution

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((num) => num > 0 && Number.isInteger(num)).map((num)=> num*num);
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);


#3

You’ll get better answers if you post any error messages you get, but anyway - you’ve used the variable name arr both on the name of the array you’re filtering as well as within the callback itself. Try changing it to something like arr.filter(a => a > 0)


#4

Thank you James :slightly_smiling_face: