fac-13 / jeth

Find jobs near you :computer:
https://jeth.herokuapp.com/
1 stars 2 forks source link

forEach + push <=> map #30

Open eliasmalik opened 6 years ago

eliasmalik commented 6 years ago

https://github.com/fac-13/jeth/blob/55aa475205ea69a649432a9c9cfd0b7e1854d083/src/logic.js#L4-L18

Using forEach to push items onto a new array is almost always equivalent to using a map.

data.map(job => ({
  title: job.title,
  ...
}))

The only case where it's not equivalent is if there's conditional logic in the body of the forEach callback which results in fewer or more elements in the new array than the original (in this case you can use reduce instead).