Write Higher Order Arrow Functions. Why is my code wrong?

I feel like this should work and does not. I cannot discern why. It should return x raised to the 2 however just returns the positive integers.

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( x => x>0 && Number.isInteger(x) ? Math.pow(x, 2) : null)
  // 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/73.0.3683.86 Safari/537.36.

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

The filter() method expect to receive true or false from the callback and keep the values for which it was true and remove the values for which it was false, you can’t use it to change the values in an array - but you can use map() to change the values in an array


thank you jedi master.

1 Like

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

Do yall know Beau on youTube???

If you feel may benefit from the YouTube channel you can write about that channel in the #reviews category