Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem

Hi everyone,

Just completed the challenge on this one - https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/functional-programming/use-higher-order-functions-map-filter-or-reduce-to-solve-a-complex-problem

My code below passes the challenge; however, I’d like to know if I can modify anything to make the code neater. Any advice will be appreciated :slight_smile: Thanks for reading!

const squareList = arr => {
    // Only change code below this line
   return arr
    .filter(num => Number.isInteger(num) && num > 0)
    .map(num => num*num)
  
  
    // Only change code above this line
  };
  
  const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
  console.log(squaredIntegers);

I’ve edited your code 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 it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

1 Like

Thanks for letting me know. Will do this in the future :slight_smile:

Define neater. The code is readable and accomplishes the task. It is fine.

Thanks :slight_smile: I am still quite new to coding/JS, so just would like to be sure.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.