Write Higher Order Arrow Functions | .reduce vs .map

Write Higher Order Arrow Functions | .reduce vs .map


Tell us what’s happening:

Please tell me what I am doing wrong/

Hi guys, I am a bit confused Why .reduce() doesn’t work here?

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.filter(arr => arr > 0  &&  Number.isInteger(arr) )
                             .reduce(arr => arr*arr);
  // change code above this line
  return squaredIntegers;
// test your code
const squaredIntegers = squareList(realNumberArray);

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36.

Link to the challenge:


Reduce is for when you want to “reduce” the array to one value, like a sum. Map goes through the array element by element and creates a new array based on some process you apply to each of those elements.

That also isn’t how you use reduce.


So reduce() doesn’t return the values that fits to the condition as an array, right?


You are correct. I believe you are confusing reduce with filter which does what you want.


Thanks, you guys are so fast! Appreciate it!