Write Higher Order Arrow Functions

Tell us what’s happening:
I don’t know if the plugin is not working well or what. This code seems OK to me and verified against other solutions I’ve seen.

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((x) => x%1 === 0);
  squaredIntegers = squaredIntegers.map((x) => x*x);
  // 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_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:

your logic seems fine… you might try using var or let instead of const for that squaredIntegers variable, seeing as how you’re reassigning it

The value of a constant cannot change through re-assignment, and it can’t be redeclared.


you probably made an oversight in this line
const squaredIntegers = arr.filter((x) => x%1 === 0);
it is x%2 not x%1. For your case the filter was basically doing nothing as every integer in the array list is divisible by 1.

let did the trick for me. thanks a lot

Sounds like you got it figured out, great!

Just a quick aside. The best practice for working with arrow functions is to only use paratheses when you have more than one parameter. See below :slight_smile:

const timesTwo = x => x * 2;  // no parens b/c only one parameter
const multiplyTwoThings = (x, y) => x * y; // parens!


You can chain .map to reduce this to one line of code and avoid switching const to let