Describe your issue in detail here.
I know my answer is correct here but just out of curiosity I am asking that “Why I was unable to do num * num in filter function”? Is filter function built like that only?
Your code so far
const squareList = arr => {
// Only change code below this line
let filteredList=arr.filter((num)=>{
if(num>0 && Number.isInteger(num)){
return num
}
})
let squareList=filteredList.map(num=>num*num)
return squareList;
// 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/119.0.0.0 Safari/537.36
Challenge Information:
Functional Programming - Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem
const squareList = arr => {
// Only change code below this line
let squareList=arr.filter((num)=>{
if(num>0 && Number.isInteger(num)){
return num * num
}
})
// Only change code above this line
};
const squaredIntegers = squareList([-3, 4.8, 5, 3, -3.2]);
console.log(squaredIntegers);
What Sanity said, Filter only take true or false (or “truthy”, link to mdn). If true, it kept the value. If false, it filters the value out of the array.