Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/strarsis/arr-group
Helper function to group array elements by a criteria callback function.
https://github.com/strarsis/arr-group
Last synced: 13 days ago
JSON representation
Helper function to group array elements by a criteria callback function.
- Host: GitHub
- URL: https://github.com/strarsis/arr-group
- Owner: strarsis
- License: mit
- Created: 2015-10-25T20:02:08.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-11-24T16:21:40.000Z (almost 9 years ago)
- Last Synced: 2024-10-18T23:55:19.721Z (about 1 month ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# arr-group
Helper function to group array elements by a criteria callback function.[![david](https://david-dm.org/strarsis/arr-group.svg)](https://david-dm.org/strarsis/arr-group)
Usage
-----
````
npm install arr-group
````The passed array has to be sorted reflecting the order the single items has to be checked for.
See code of [group-numbers](https://github.com/strarsis/group-numbers/blob/master/index.js) about how arr-group is used.Arguments
---------
### arr
The array to be grouped.
It has to be sorted reflecting the order the single has to be checked for.### isNextFunction
Callback that should return true if the passed current element is following the passed previous element.
````
function(currentItem, previousItem) {
[...]
return true; // current item is the following the previous item
[...]
return false; // current item is not following the previous item
}
````### returnSingleElements
Whether to return single elements in the array as single elements or in an array (of a single element).
Defaults to true.