Array filter and mapping exercise problem

Tell us what’s happening:
the code is not working even though it should i even tried the one in the help section please help.

Your code so far


const squareList = (arr) => {
// Only change code below this line
const squareList = arr =>
arr.filter(num => num > 0 && num % parseInt(num) === 0).map(num => Math.pow(num, 2));
return arr;
// Only change code above this line
};

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

Your browser information:

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

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

Link to the challenge:

Filter, map etc create a new array, they don’t mutate. You’re returning the original array instead of the result of mapping and filtering it.

also pretty big issue here: when you have arrow function, and don’t use {} around the function body, that means you are doing implicit return. But this squareList function is never called.

You have a squareList function definition two lines above, that function is just returning arr

let’s format this nicely, maybe it’s easier to see:

const squareList = (arr) => {
  // Only change code below this line
  const squareList = arr =>
    arr.filter(num => num > 0 && num % parseInt(num) === 0).map(num => Math.pow(num, 2));
  return arr;
  // Only change code above this line
};

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

i would appreciate if you could fix the minor change cause it’s not easy to understand.

it’s a minor change

there was already a function definition, if you add a new function definition, then you are creating a function that is never called

const funcA= (arr) => {
  // Only change code below this line
  const funcB = arr =>
    arr.filter(num => num > 0 && num % parseInt(num) === 0).map(num => Math.pow(num, 2));
  return arr;
  // Only change code above this line
};

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

here I have changed the names of the variables to funcA and funcB to understand better, but other than that it’s your code:
the code you found in the editor had already the definition of funcA, you just had to make sure it returned the right thing, without creating a new function

instead you created funcB, the issue is that it may or may not have the correct logic, but funcB is never called, leaving funcA just returning arr without changing it

if you understand this, and fix it, you are pretty near the solution of the challenge

thanks a lot,I just noticed what i was doing wrong.