Tell us what’s happening:
Describe your issue in detail here.
Hi, I’m having a tough time filtering out all of the correct numbers in the list (see const squaredIntegers) to then reach the conclusion of this problem.
1: I first tried to create a local variable of numbersToSquareFinal to contain everything I needed to perform on the elements in the array. I went ahead and ran arr.slice() just to preserve/not mutate the original array.
2: After, I ran the first filter() method that seemed to work, somewhat. I wanted to divide each number I passed through and as long as the number could be divided by 1 and return back no remainder, as per the filter(), then that would fit the category of filtering out the numbers with decimals.
3: I ran another filter(), this time passing through each number, and then validating if it was greater than -1 or not, to further filter down that array and refine what numbers are to be squared.
4: Then, I ran a .map() method to square each number.
That’s just me working it out as best I can on my end. I’m thankful that I’ve understood how each of these methods/functions work thus far, but you can see where I’m starting to get somewhat lost. Any tips/helpful pointers greatly appreciated, I’ll keep working on it. I’m just feeling confused and could use the help! (I’m struggling to understand how this isn’t working out.)
Thank you!!
**Your code so far**
const squareList = arr => {
// Only change code below this line
let numbersToSquareFinal = arr.slice()
.filter(number => number % 1 === 0)
.filter(x => { return x > -1; })
.map(number => number * number)
console.log(numbersToSquareFinal)
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Functional Programming - Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem
Link to the challenge: