arrayreduce

Array reducing utility.

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
arrayreduce
202.1.08 years ago9 years agoMinified + gzip package size for arrayreduce in KB

Readme

arrayreduce


!Build Statusbdtravisshieldurlbdtravisurl !Code Climatebdcodeclimateshieldurlbdcodeclimateurl !Code Coveragebdcodeclimatecoverageshieldurlbdcodeclimateurl !npm Versionbdnpmshieldurlbdnpmurl


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.

Links