This is a really excellent point Andrew, and something I totally missed while I was writing it. Thank you for the information and examples!
For the record, it's also possible by spreading the object, although it won't work everywhere at the moment, depending on your ES version:
students .map(s => ({...s, age: s.age + 1})) .filter(s => s.age < 12) .forEach(s => console.log(s))
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)
It's beautiful :O
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a really excellent point Andrew, and something I totally missed while I was writing it. Thank you for the information and examples!
For the record, it's also possible by spreading the object, although it won't work everywhere at the moment, depending on your ES version:
Clean it even more by extracting callbacks
It's beautiful :O