I am trying to dynamically split an array of objects into groups based on values of a property.
Here is an example of the input:
`input = [
{"name": "john", "location": "first"},
{"name": "steve", "location": "first"},
{"name": "paul", "location": "another"},
{"name": "tony", "location": "random"},
{"name": "ant", "location": "random"}
]`
and the desired output:
`solution(input, location) = [
first: [{"name": "john", "location": "first"},
{"name": "steve", "location": "first"}],
another: [{"name": "paul", "location": "another"}],
random: [{"name": "tony", "location": "random"},
{"name": "ant", "location": "random"}]
]`
I do not know the values that location can be (but i do know the key name)
I am trying to avoid using any external libs, (this is inside an angular 5 project) but if it makes it drastically easier then I am not against it.
Thanks in advance