Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/okunishinishi/node-arrayreduce

Node.js module for array reducing.
https://github.com/okunishinishi/node-arrayreduce

Last synced: 2 months ago
JSON representation

Node.js module for array reducing.

Awesome Lists containing this project

README

        

arrayreduce
==========

[![Build Status][bd_travis_shield_url]][bd_travis_url]
[![Code Climate][bd_codeclimate_shield_url]][bd_codeclimate_url]
[![Code Coverage][bd_codeclimate_coverage_shield_url]][bd_codeclimate_url]
[![npm Version][bd_npm_shield_url]][bd_npm_url]

[bd_repo_url]: https://github.com/okunishinishi/node-arrayreduce
[bd_travis_url]: http://travis-ci.org/okunishinishi/node-arrayreduce
[bd_travis_shield_url]: http://img.shields.io/travis/okunishinishi/node-arrayreduce.svg?style=flat
[bd_license_url]: https://github.com/okunishinishi/node-arrayreduce/blob/master/LICENSE
[bd_codeclimate_url]: http://codeclimate.com/github/okunishinishi/node-arrayreduce
[bd_codeclimate_shield_url]: http://img.shields.io/codeclimate/github/okunishinishi/node-arrayreduce.svg?style=flat
[bd_codeclimate_coverage_shield_url]: http://img.shields.io/codeclimate/coverage/github/okunishinishi/node-arrayreduce.svg?style=flat
[bd_gemnasium_url]: https://gemnasium.com/okunishinishi/node-arrayreduce
[bd_gemnasium_shield_url]: https://gemnasium.com/okunishinishi/node-arrayreduce.svg
[bd_npm_url]: http://www.npmjs.org/package/arrayreduce
[bd_npm_shield_url]: http://img.shields.io/npm/v/arrayreduce.svg?style=flat
[bd_bower_badge_url]: https://img.shields.io/bower/v/arrayreduce.svg?style=flat

Array reducing utility.


Installation
-----

```bash
npm install arrayreduce --save
```


Usage
-------

+ [Concat Array](#concat-array)
+ [Boolean And](#boolean-and)
+ [Boolean Or](#boolean-or)
+ [Index By Attr](#index-by-attr)

### Concat Array

`arraysort.arrayConcat()` create a function which reduce entries as concatenated array.

```javascript
"use strict";

const arrayreduce = require('arrayreduce');

// Define a reducing function.
let arrayConcat = arrayreduce.arrayConcat();

// Execute sorting.
let values = ['foo', ['bar', 'baz']].reduce(arrayConcat, []);
console.log(values); // -> ['foo', 'baz', 'bar']

```

### Boolean And

`arraysort.booleanAnd()` create a function which reduce entries with and condition.

```javascript
"use strict";

const arrayreduce = require('arrayreduce');

// Define a reducing function.
let booleanAnd = arrayreduce.booleanAnd();

// Execute reducing.
let result = [true, false, true].reduce(booleanAnd, true);
console.log(result); // -> false

```

### Boolean Or

`arraysort.booleanOr()` create a function which reduce entries with and condition.

```javascript
"use strict";

const arrayreduce = require('arrayreduce');

// Define a reducing function.
let booleanOr = arrayreduce.booleanOr();

// Execute reducing.
let result = [true, false, true].reduce(booleanOr, true);
console.log(result); // -> true

```

### Index By Attr

`arraysort.indexByAttr()` create a function which reduce entries to index object.

```javascript
"use strict";

const arrayreduce = require('arrayreduce');

// Define a reducing function.
let indexByAttr = arrayreduce.indexByAttr();

// Execute indexing.
let index = [
{id: 1, name: 'foo'},
{id: 2, name: 'bar'}
].reduce(indexByAttr('id'), {});
console.log(index); // -> {'1': {id: 1, name: 'foo'}, '2': {id: 2, name: 'bar'}}

```

License
-------
This software is released under the [MIT License](https://github.com/okunishinishi/node-arrayreduce/blob/master/LICENSE).

Links
------

+ [arrayfilter](https://github.com/okunishinishi/node-arrayfilter)
+ [arraysort](https://github.com/okunishinishi/node-arraysort)