group-by-prototype
v1.0.1
Published
Group an Array of objects by key or with a function.
Downloads
7
Maintainers
Readme
group-by-prototype
Group an Array of objects by key or with a function.
Installation
npm install --save group-by-prototype
Usage
example reading last 50 lines of a file
require('group-by-prototype');
const data = [
{
"key": "word",
"value": "hello"
}, {
"key": "word",
"value": "world"
}, {
"key": "number",
"value": 2
}
];
let groupedByKey = data.groupBy("key");
let groupedEvenOdd = [4,9,5,8,1,6,3,0,2,7].groupBy((x, i) => { return x % 2 === 0 ? "even" : "odd"});
/*
{
"even": [4,8,6,0,2],
"odd": [9,5,1,3,7]
}
*/
let groupedIndexEvenOdd = [8,6,4,2,0,1,3,5,7,9].groupBy((x, i) => { return i % 2 === 0 ? "even" : "odd"});
/*
{
"even": [4,5,1,3,2],
"odd": [9,8,6,0,7]
}
*/
Contributing
- Fork it on Github https://github.com/alexbbt/group-by-prototype
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D