Comparing version 1.5.0 to 1.6.0
@@ -10,3 +10,3 @@ /** | ||
/** | ||
* Hashes an array of objects based on the value of a provided common key. | ||
* Hashes an array based on the value of a provided common key. | ||
* @function module:101/index-by | ||
@@ -13,0 +13,0 @@ * @param {array|function|string} arr|indexer - array of objects to be indexed |
{ | ||
"name": "101", | ||
"version": "1.5.0", | ||
"version": "1.6.0", | ||
"description": "common javascript utils that can be required selectively that assume es5+", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
![101](http://i.imgur.com/MFrmMt6.png) | ||
=== | ||
[![NPM](https://nodei.co/npm/101.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/101/) | ||
[![NPM](https://nodei.co/npm/101.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/101/) | ||
@@ -324,3 +324,41 @@ [![Build Status](https://travis-ci.org/tjmehta/101.svg?branch=master)](https://travis-ci.org/tjmehta/101) | ||
flip(prefix)('hello', '_'); // "_hello" | ||
``` | ||
## groupBy | ||
Hashes an array into groups based on the value of a provided common key. | ||
Works nicely with `pluck` and `reduce`. | ||
```js | ||
var arr = [ | ||
{id: 1, foo: 'bar'}, | ||
{id: 2, foo: 'qux'}, | ||
{id: 3, foo: 'qux'} | ||
]; | ||
groupBy(arr, 'foo') | ||
/* | ||
{ | ||
bar: [ | ||
{id: 1, foo: 'bar'} | ||
], | ||
qux: [ | ||
{id: 2, foo: 'qux'}, | ||
{id: 3, foo: 'qux'} | ||
] | ||
} | ||
*/ | ||
// always provide initial value when using with reduce! | ||
arr.reduce(groupBy('foo'), {}) // assumes pluck if passed string | ||
arr.reduce(groupBy(pluck('foo')), {}) // also accepts function | ||
/* | ||
{ | ||
bar: [ | ||
{id: 1, foo: 'bar'} | ||
], | ||
qux: [ | ||
{id: 2, foo: 'qux'}, | ||
{id: 3, foo: 'qux'} | ||
] | ||
} | ||
*/ | ||
``` | ||
@@ -433,7 +471,9 @@ | ||
var arr = [ | ||
{foo: 'bar'}, | ||
{foo: 'qux'} | ||
{foo: 'bar'}, | ||
{foo: 'qux'} | ||
]; | ||
indexBy(arr, 'foo') // {bar: {foo: 'bar'}, qux: {foo: 'qux'}} | ||
arr.reduce(indexBy('foo'), {}) // assumes pluck if passed string | ||
arr.reduce(indexBy(pluck('foo')), {}) // also accepts function | ||
// {bar: {foo: 'bar'}, qux: {foo: 'qux'}} | ||
// always provide initial value when using with reduce! | ||
@@ -440,0 +480,0 @@ arr.reduce(indexBy(pluck('foo')), {}) // {bar: {foo: 'bar'}, qux: {foo: 'qux'}} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
59096
1229
861