Grrr…I’m now going round and round in circles with this. I started with my code. I knew I wanted to filter the list for numbers greater than 0 and only integers not floating point. So that was the .filter method.
then I need to .map method a new array squaring the number. My original code didn’t work (still a newbie and I get confused about how to string everything together still). I read all the previous help posts and made changes, still wasn’t working. In the end I looked at the gethelp post and this below is the solution from the get help post. It is still not working.
I keep getting back
// running tests The function should return an
array
.
squareList([4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2])
should return
[16, 1764, 36]
.
squareList([-3.7, -5, 3, 10, 12.5, 7, -4.5, -17, 0.3])
should return
[9, 100, 49]
. // tests completed // console output undefined
I have been working at this for ages now and am ready to throw the screen out the window…lol
const squareList = (arr) => {
// Only change code below this line
arr
.filter(num => num > 0 && num % parseInt(num)===0)
.map(num=>Math.pow(num, 2));
// 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/81.0.4044.113 Safari/537.36
.
Challenge: Use Higher-Order Functions map, filter, or reduce to Solve a Complex Problem
Link to the challenge: