Tell us what’s happening:
I am struggling to understand how to chain the arrow functions (if indeed that’s what i’m supposed to be doing) so that I can exclude the decimal numbers from my new array.
I’ve tried getting "Number.isInteger(arr)"
or "Number.isInteger(x)"
(where x is defined) but I don’t know if this is the right approach and I also don’t know how I’m supposed to add it to my code already.
I’ve seen the solution and it’s quite different to mine. I’m at the point where I’m squaring only the positive numbers, but I can’t get it to only do the integers.
I’m sure this is insanely obvious to most people but I’ve been sitting here for an hour and a bit trying different combos. I was trying parseInt(x, 10)
or parseInt(num, 10)
for a long while to no avail, and I did Math.round
to even less avail.
Thanks in advance for your help.
Your code so far
const realNumberArray = [4, 5.6, -9.8, 3.14, 42, 6, 8.34, -2];
const squareList = (arr) => {
"use strict";
// change code below this line
const squaredIntegers = arr.filter (x => x > 0).map(x => x * x);
// change code above this line
return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
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/73.0.3683.103 Safari/537.36
.