Something wrong with ES6: Write Higher Order Arrow Functions

Hi,

What is wrong with this? I get the message that:“isInteger is not defined”.

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 = Number.filter((isInteger) && Number.filter> 0)
  // change code above this line
  return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers

Look at the correct usage of .isInteger().

1 Like

I tried this now but does not seem to work in this area:" squaredIntegers should be [16, 1764, 36]"

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 myFunction = (num) =>{
  if(Number.isInteger(num) == true && num > 0) {
  return num * num;
  }
}  

 let squaredIntegers = arr.map(myFunction);
  // change code above this line
  return squaredIntegers;
};
// test your code
const squaredIntegers = squareList(realNumberArray);
console.log(squaredIntegers);

If I recall correctly, you need to filter out the numbers that are not positive integers.

One other comment regarding Number.isInteger(num) == true: This isn’t technically wrong, but it is unnecessary. You don’t need to check for == true because thingThatEqualsTrue is true and thingThatEqualsTrue == true is also true.

1 Like

As Number.isInteger() method was not presented yet, I went around using math.floor:

Math.floor(val) == val && val > 0 ? squaredIntegers.push(val * val) : "Not invited to the party. Get out of my array!"})
1 Like