177. Implement Object.groupBy()
分享给更多人
中等难度 -通过 / -执行
Object.groupBy()
allows us to easily group array items,
please try to implement it by yourself.
const items = [ { id: 1, kind: 'a', }, { id: 2, kind: 'b', }, { id: 3, kind: 'a', }]const groups = Object.groupBy(items, ({kind}) => kind)// {// a: [// {// id: 1,// kind: 'a'// },// {// id: 3,// kind: 'a'// }// ],// b: [// {// id: 2,// kind: 'b'// }// ]// }