Write Higher Order Arrow Functions_help

Tell us what’s happening:

How would I filter the positive integers only?

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(squaredIntegers);
  // 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 (X11; CrOS x86_64 12105.100.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.144 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/write-higher-order-arrow-functions/

without atempting to solve the challenge and just answer your question you can do the following:

let positiveInts = realNumberArray.filter(x => x > 0) //(es6) 
```
edit i just looked at the challenge cause i cant sleep and u dont want decimals so you can do 
```
let positiveInts = realNumberArray.filter(x => x > 0 && Number.isInteger(x))
```

could you use Math.Floor instead of Number.isInteger

i think you could but not with filter as its not giving a rule to filter with its changing numbers it could work with map but with mean using additional higher order functions

let positiveInts = realNumberArray.filter(x => x > 0).map(x => x = Math.floor(x))

is how you would be using Math.floor the problem is it wants you to filter out the non intergers (decimals) not change them to be intergers so you end up with additonal numbers you dont want to complete the challenge.

1 Like

a use of Math.floor() could be to do x === Match.floor(x), this inside filter(), as a way to remove non whole numbers

ah i went and replaced my code of Number.isInt with that and it didnt work i had only just woken up so maybe i got did somin wrong and didnt notice my bad

It okay. Thanks for the insight!