npm.io
0.5.0 • Published 5 years ago

@pansy/group-by

Licence
MIT
Version
0.5.0
Deps
0
Size
7 kB
Vulns
0
Weekly
0

@pansy/group-by

根据迭代函数返回的值对数组进行分组。

安装

// npm
npm install @pansy/group-by --save

// yarn
yarn add @pansy/group-by

使用

import groupBy from '@pansy/group-by';

const list = [
  { module: 'module1', action: 'action1' },
  { module: 'module1', action: 'action2' },
  { module: 'module2', action: 'action1' }
];

console.log(groupBy(list, item => item.module));

// => {
// =>   module1: [
// =>     { module: 'module1', action: 'action1' },
// =>     { module: 'module1', action: 'action2' },
// =>   ],
// =>   module2: [
// =>     { module: 'module2', action: 'action1' }
// =>   ]
// => }