Skip to main content
tweak
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28

I fully endorse the approach in this answer, avoiding the duplicate ID and potentially using a loop rather than a reduce. The Map suggested there is a perfectly reasonable alternative to plain objects or groupBy as well.

I fully endorse the approach in this answer, avoiding the duplicate ID and potentially using a loop rather than a reduce. The Map suggested there is a perfectly reasonable alternative to plain objects or groupBy as well.

I fully endorse the approach in this answer, avoiding the duplicate ID and using a loop rather than a reduce. The Map suggested there is a perfectly reasonable alternative to plain objects or groupBy as well.

add endorsement
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28

I fully endorse the approach in this answer, avoiding the duplicate ID and potentially using a loop rather than a reduce. The Map suggested there is a perfectly reasonable alternative to plain objects or groupBy as well.


I fully endorse the approach in this answer, avoiding the duplicate ID and potentially using a loop rather than a reduce. The Map suggested there is a perfectly reasonable alternative to plain objects or groupBy as well.

mention groupBy allocation overhead
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28

Speaking of which, groupBy will incur some allocation overhead for those unnecessary arrays. I'd expect reduce to be fastest, but this is just a hunch and I haven't benchmarked anything. It probably doesn't matter a whole lot since it's back in linear time complexity territory either way, and departments is probably on the small side, but worth keeping in mind.

Speaking of which, groupBy will incur some allocation overhead for those unnecessary arrays. I'd expect reduce to be fastest, but this is just a hunch and I haven't benchmarked anything. It probably doesn't matter a whole lot since it's back in linear time complexity territory either way, and departments is probably on the small side, but worth keeping in mind.

mention two passes
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28
Loading
add alternatives to groupBy
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28
Loading
make departmentsById visible
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28
Loading
edited body
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28
Loading
add example of refactoring map/filter
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28
Loading
note about flatMap
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28
Loading
Source Link
ggorlen
  • 4.2k
  • 2
  • 19
  • 28
Loading