Write Higher Order Arrow Functions -- error msg

Write Higher Order Arrow Functions -- error msg
0.0 0


Tell us what’s happening:

I keep getting the error “16 is not a function”. Can someone explain why I’m getting this…?

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 = realNumberArray.filter((num) => num % 1 == 0 && num > 0 && realNumberArray.map(squareList = num*num));
  // change code above this line
  return squaredIntegers;
// test your code
const squaredIntegers = squareList(realNumberArray);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:


Heya! I’m not sure why you’re getting that particular error.

That being said, I think your hiccup is trying to combine filter() and map() in a single function call. I might suggest calling filter() and map() sequentially (i.e. filter the array, then map it).

You’re also assigning squareList to a new value at the end of the call. I’m not sure what you’re thinking this will do, but the statement

squareList = num*num

doesn’t make sense to me.

I hope this helps. Good Luck!


You’ve nearly got it tbf…

realNumberArray.filter((num) => num % 1 == 0 && num > 0 && realNumberArray.map(squareList = num*num));

This is actually very close but it seems like you have a slight misunderstanding of how map and filter work. Map and filter are both called on arrays and produce an array as a result. Functional programming in Javascript which is what this basically is normally uses a popular method called chaining. Basically
array.method1.method2 will apply method1 then method 2 to this array.

Therefore looking at this problem. It tells us to do two things. filter out only positive integers and then map over the resulting array and square each item.

Therefore the line you are looking for looks something like this.

realNumberArray.filter(item => item % 1 == 0 && item > 0).map(item => item * item);

This is telling the program to first filter the realNumberArray by the specified rules and then we apply map to the filtered elements where for each element in map we square it. If you’re still confused about how map and filter work check out their MDN docs. Also when you hit react map, filter and reduce become very useful and make it a lot easier to do things. So keep at it!!!