arrayreduce
v2.1.0
Published
Array reducing utility.
Downloads
10,346
Readme
arrayreduce
Array reducing utility.
Installation
npm install arrayreduce --save
Usage
Concat Array
arraysort.arrayConcat()
create a function which reduce entries as concatenated array.
"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.
"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.
"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.
"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.