Skip to content

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

Notifications You must be signed in to change notification settings

KoryNunn/to-groups

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 ]
}

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages