@jswork/next-group-by
v1.1.6
Published
Creates an object composed of keys generated from the results of running each element of collection thru iteratee.
Downloads
81
Maintainers
Readme
next-group-by
Creates an object composed of keys generated from the results of running each element of collection thru iteratee.
installation
npm install -S @jswork/next-group-by
usage
import '@jswork/next-group-by';
const arr = [
'sljflsdjf.jpg',
'bb.jpg',
'bc.jpg',
'ccsdf.jpg',
'ccsdf.jpg',
'http://www.agc.cn/1.jpg',
'sldjfsld.jpg',
'wx://localResource'
];
const res = nx.groupBy(arr, (item) => {
var rs = item.split('://');
return rs.length === 2 ? rs[0] : 'normal';
});
// result
{
normal: [
'sljflsdjf.jpg',
'bb.jpg',
'bc.jpg',
'ccsdf.jpg',
'ccsdf.jpg',
'sldjfsld.jpg'
],
http: [ 'http://www.agc.cn/1.jpg' ],
wx: [ 'wx://localResource' ],
__computed__: {
normal: 6,
http: 1,
wx: 1
}
}
license
Code released under the MIT license.