DEV Community

Discussion on: Array Iteration for Beginners

Collapse
 
frankwisniewski profile image
Frank Wisniewski

we are in the year 2022!!

const greaterThanThree = num => num > 3
Enter fullscreen mode Exit fullscreen mode
Collapse
 
fjones profile image
FJones

To be fair (despite the formatting), it does say "for beginners", and the prevailing thought is still that beginners don't like arrow functions.

That said, if we want to do this, might as well do it right:

const greaterThan = than => num => num > than;
const greaterThanThree = greaterThan(3);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
frankwisniewski profile image
Frank Wisniewski

Well then I'd rather do it that way

const isGreaterThan = num => value => value > num
let list = [1,2,3,4,5]    
console.log(
  list.filter(isGreaterThan(3)) 
)
Enter fullscreen mode Exit fullscreen mode