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

Tell us what’s happening:
I am stuck on this challenge despite looking at the solution I cant seem to solve the problem, Where could I be going wrong ? I am having the same identical code like with the solutions provided but it does not get the job done kindly I need your help on this guys.

``````
const squareList = (arr) => {
// Only change code below this line
return arr;
const squareList = (arr) => {
const positiveIntegers = arr.filter(num => {
return num >= 0 && Number.isInteger(num);
});
const squaredIntegers = positiveIntegers.map(num => {
return num ** 2;
});
return squaredIntegers;
};
// Only change code above this line
};

const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);

``````

User Agent is: `Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36`.

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

everything after the return statement is not executed. Your function first line is `return arr`. So `arr` is returned, and the function stops.

1 Like

Like ieahleen said, your return statement means nothing else inside that function is being executed.

You also have unnecessarily repeated the function definition “squareList” and created an entirely new function inside the outer “squareList” function, making it somewhat confusing to read. So I can understand where you were confused, haha!!

Your inner squareList function looks fine though, so just copy that whole function, move it outside of the “outer” squareList function, and delete that outer one. Then it should work.

1 Like

Thanks I did the changes and worked perfectly

1 Like

Thank you for your assistance I was able to solve it

Hi, where exactly are you stuck on, the answer should look more like this;

const squareList = (arr) => {

// Only change code below this line

const positiveIntegers = arr.filter(num => {

return num >= 0 && Number.isInteger(num);

});

const squaredIntegers = positiveIntegers.map(num => {

return num ** 2;

});

return squaredIntegers;

return arr;

};

// Only change code above this line

const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);

1 Like

You legend! Thanks so much! I must be tired, because I’ve been banging my head over this all day!