1.0.0 • Published 8 years ago

to-groups v1.0.0

Weekly downloads
2
License
ISC
Repository
github
Last release
8 years ago

to-groups

Take an array of items, and produce an object with groups of its elements based on a hashing function.

Usage

var toGroups = require('../');

var grouped = toGroups([1,2,3,576,78,45,32,2,3], function(item){
        return String(Math.floor(item / 10) * 10) + '-' + String(Math.ceil(item / 10) * 10 - 1);
    });

grouped -> {
    '0-9':[ 1, 2, 3, 2, 3 ],
    '30-39':[ 32 ],
    '40-49':[ 45 ],
    '70-79': [ 78 ],
    '570-579':[ 576 ]
}
1.0.0

8 years ago