Notes
- Person is the only resource type that is adjacent aggregated
- Place is NOT suppose to be aggregated, BUT we are going to be implementing the function with a required types specification to allow for different types to be specified such that we don’t shoot ourselves in the foot when we submit the project. And we will make clear what we thought and how it can be rectified with the required types option of the strategy in the usage of the example.
- Type and Order are the keys to the kingdom. Name is almost irrelevant as it does not have an impact on the business rules. It’s simply used as a part of deriving the aggregate data. That’s it.
- This is meant to be a testable and flexible function. We will write test(s) for it.
- Input:
const resources = [{
type: 'Person',
order: 1,
name: 'Brian',
}, {
type: 'Place',
order: 2,
name: 'Ohio',
}, {
type: 'Place',
order: 12,
name: 'Ohio',
}, {
type: 'Person',
order: 14,
name: 'Sarah',
` }, {
type: 'Person',
order: 199,
name: 'Sam',
}, {
type: 'Person',
order: 19,
name: 'Eric',
}, {
type: 'Place',
order: 20,
name: 'Home',
}
];
[
{
"type": "Person",
"order": 1,
"people": [
"Brian"
]
},
{
"type": "Place",
"order": 2,
"name": "Ohio"
},
{
"type": "Place",
"order": 12,
"name": "Ohio"
},
{
"type": "Person",
"order": 19,
"people": [
"Sarah",
"Eric"
]
},
{
"type": "Place",
"order": 20,
"name": "Home"
},
{
"type": "Person",
"order": 199,
"people": [
"Sam"
]
}
]
Approach Tasks(numbers indicate pomodoro units)
Utility Function(s) Specs
- Aggregate Adjacent Resources : 0-n resources must be grouped in place based on there asc order and there common type(if that type is requested to be aggregated).
- Order the resource collection ascending
- Iterate over the resource collection doing the following:
- Resource Is Not Of A Required Type - This resource(like one of type
Place) is not going to be be grouped so it does not need to be tracked. However this means that the currently grouped resources need to be stored away and the collection reset. Then also store the current resource as is.
- Current Resource Type Differs From Previous - A previous resource grouping needs to be stored as an aggregate resource since the current valid resource is of a different type. Then start a new grouping with the valid resource
- Current resource is first valid or a successive valid of the same Type - We can go ahead and append on the current resource to the resource grouping. And save the current resource as the previous resource.
- At end of loop body, derive previous type and order if the previous resource is set, which is not the case if the last resource was not a required type
- Before function is left we need to attempt create and store an aggregate resource for the last resource grouping
Utility Function(s) Unit Tests(or cases)
- Aggregate Adjacent Resources
- Interface:
aggregateAdjacentResources(resources, strategy)
- The following three test cases should all be covered by the default I/O data that's provided
- Test that some
Person resources are grouped
- Test that some
Person resources are not grouped based on the natural ordering
- Test that
Place resources are not grouped at all
- Added more cases that are felt to be relevant as the implementation proceeds