DEV Community

Discussion on: Useful JS functions you aren't using: Array.filter

 
tjinauyeung profile image
Tjin

Clean it even more by extracting callbacks

const addYearToAge = person => ({...person, age: person.age + 1})
const isUnderTwelve = person => person.age < 12

students
  .map(addYearToAge)
  .filter(isUnderTwelve)
  .forEach(console.log)
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
vidup profile image
Victor Dupuy

It's beautiful :O