Write Higher Order Arrow Functions - I'm lost

Write Higher Order Arrow Functions - I'm lost
0

#1

So I am stuck on this task and I am losing my mind. Please someone point me in the right direction. I’ve watched countless YT videos and read my 4 JS books and still I can not crack it so I am at the point where I need to ask for help.

So please help.

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;

  const filterTheArray = realNumberArray.filter(
    i => i > 0 && Math.floor(i) == i && Math.ceil(i) == i
  );
  console.log(filterTheArray);

  const squaredNumber = filterTheArray.map((i) => i ** 2);
  console.log(squaredNumber);

  // 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 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15.

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


#2

Your code is correct. You are just returning the wrong variable. Return squaredNumber instead of squaredIntegers.


#3

This is something that you need to check: const squaredIntegers = arr;

The challenge is asking you to store the computed values in the squaredIntegers variable, but instead you are storing “arr”, and because you are using const to declare the variable, your code can’t pass the test.

But you are in the right direction, using filter and map is the way to solve the challenge, just make sure that the returned values are stored in the squaredIntegers variable.


#4

Thanks both, I got it now and passed. It was late here in the UK when trying to solve this one :slight_smile:


#5

What do you mean by this statement?