Attempt to reduce the complexity of the combining function.
Proposal / demo of how it could look instead.
Needs testing and verification because I've never actually seen or interacted with the WebsocResponse[]
Strategy
Use map and flat to generate a flattened array of enhanced sections: sections that have contextual metadata about the school, department, and course they're in
Use reduce to create an array of schools by iterating through enhanced sections and handling each appropriately.
Attempt to find some "part" of the section in the accumulated array of schools
If it doesn't exist, then add that "part" of the section to the corresponding property of the accumulated schools
Otherwise, index into the found "part" and repeat
Notes
Doesn't replace the current implementation yet because idk how to test it
This solution intends to "abuse" object references to push to the correct arrays, but I'm not sure how this actually plays out in reality -- i.e. where we should make deep copies or keep original references
Why
Easier to read and reason about for my smol brain
No more dependence on the external object-hash library
Better utilizes TypeScript null checking and guarding to prevent superfluous optional chaining and re-indexing of previously processed arrays
Summary
Attempt to reduce the complexity of the combining function. Proposal / demo of how it could look instead. Needs testing and verification because I've never actually seen or interacted with the
WebsocResponse[]
Strategy
map
andflat
to generate a flattened array of enhanced sections: sections that have contextual metadata about the school, department, and course they're inreduce
to create an array of schools by iterating through enhanced sections and handling each appropriately.Notes
push
to the correct arrays, but I'm not sure how this actually plays out in reality -- i.e. where we should make deep copies or keep original referencesWhy
object-hash
library