<分区>
我正在尝试根据属性值动态将对象数组拆分为多个组。
这是一个输入示例:
`input = [
{"name": "john", "location": "first"},
{"name": "steve", "location": "first"},
{"name": "paul", "location": "another"},
{"name": "tony", "location": "random"},
{"name": "ant", "location": "random"}
]`
和期望的输出:
`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"}]
]`
我不知道位置可以是什么值(但我知道键名)
我试图避免使用任何外部库, (这是在一个 Angular 5 项目中) 但如果它使它变得非常容易,那么我并不反对。
提前致谢