JSPM

group-by

0.0.1
    • ESM via JSPM
    • ES Module Entrypoint
    • Export Map
    • Keywords
    • License
    • Repository URL
    • TypeScript Types
    • README
    • Created
    • Published
    • Downloads 3038
    • Score
      100M100P100Q107741F

    Group an array by property values or callback

    Package Exports

    • group-by

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (group-by) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    group-by

    Group an array of values by property or callback function.

    Installation

    $ component install component/group-by
    $ npm install group-by

    API

    groupBy(array, prop)

    Map returning a new array:

    var groupBy = require('group-by');
    
    var log1 = { type: 'log', version: '1.0.0' };
    var log2 = { type: 'log', version: '1.1.0' };
    var log3 = { type: 'log', version: '1.3.0' };
    var app1 = { type: 'app', version: '1.0.0' };
    var app2 = { type: 'app', version: '1.1.0' };
    
    var nodes = [log1, app1, log2, log3, app2];
    
    groupBy(nodes, 'type');

    yields:

    { log: 
       [ { type: 'log', version: '1.0.0' },
         { type: 'log', version: '1.1.0' },
         { type: 'log', version: '1.3.0' } ],
      app: 
       [ { type: 'app', version: '1.0.0' },
         { type: 'app', version: '1.1.0' } ] }

    groupBy(array, fn)

    Group with an arbitrary fn, returning a key name:

    groupBy(users, function(user){
      return user.pets.length
        ? 'hasPets'
        : 'noPets';
    })

    License

    MIT