# Write Higher Order Arrow Functions /solved it but still have a question

Tell us what’s happening:

``````
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34];
const squareList = (arr) => {
"use strict";
// change code below this line
const positive =realNumberArray.filter(realNumberArray=>
realNumberArray>0 && realNumberArray % 1==0);
const squaredIntegers = positive.map(x=>x*x);

// change code above this line
return squaredIntegers;
};
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
``````

User Agent is: `Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36`.

So I solved it like this, but code seems messy and I don’t understand what `const squareList = (arr) => {` at start of the code means. why do they even need arr variable initially when I ended up not using it at all??
Can anyone tidy up my code so that it will look nicer and cleaner?? Thanks!!

Your `squareList` function takes an array as a parameter and transforms this array as an array containing the squared integers.

`const squareList = (arr) => { ... }` means : create a function called square that takes an array as a parameter

You’ve done a little mistake. It shouldn’t be `realNumberArray` but `arr`.
In fact, the goal of that function is to be reusable.

Here is a cleaner version :

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

I just replaced `realNumberArray` with `arr` and chained the array methods.

3 Likes

THank you so much!!
I didn’t know that I can combine those two filter and map arrow functions with dot as well.
Btw, in the last line,
`const squrardIntegers = squareList(realNumberArray);`
I don’t quite get this. Can we just test the function like
`squareList (realNumberArray);` ?
since it will return `squaredIntegers`.
Also, I don’t understand where `number` came from. Shouldn’t it be `array` to be reusable? or are you making new parameter for the sake of reusabiility?
So either number or x in this line below,

``````const squaredIntegers = arr.filter(number => number > 0 && number % 1 === 0)
.map(number => number*number);
``````

are we making new local parameter inside of squaredIntegers function? I found it it works when I put x or y instead of number.