I´m having an issue with this topic.
Where does the num
come from? How does the function knows that num
refer to the elements of the array? As I see, there was no where when num
was declared.
What do I think?
num
can be replaced with any random word, because the way filter()
woks is assigning array elements to be worked on with the function. But its just a speculation.
const squareList = (arr) => {
"use strict";
const squaredIntegers = arr.filter( (num) => num > 0 && num % parseInt(num) === 0 ).map( (num) => Math.pow(num, 2) );
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);
Thanks in advance!