Group orders by status
Transform a flat order list into stable status groups without mutating the input.Description
Requirements
The solution exports a callable function named groupOrdersByStatus.
Each order appears in the array whose object key exactly matches that order's status.
Orders within each status group retain their original relative order.
The returned object contains keys only for statuses present in the input.
An empty input array returns an empty object.
Calling the function does not mutate the input array or any input order object.
Repeated statuses
[{ id: 'a', status: 'pending' }, { id: 'b', status: 'done' }, { id: 'c', status: 'pending' }]{ pending: [{ id: 'a', ... }, { id: 'c', ... }], done: [{ id: 'b', ... }] }The pending orders remain in the same order in which they appeared in the input.
Constraints
Do not mutate the input array or its order objectsCreate groups only for statuses present in the inputReturn an empty object for an empty array
Hints
Hint 1
Choose an accumulator whose keys can be created as new statuses appear.
Hint 2
Process orders from left to right so appending naturally preserves their relative order.
Hint 3
Place each original order into the collection associated with its status without changing the source.