npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

array-groups

v0.1.1

Published

Tool to organize arrays of objects in sub-arrays grouped by value-ranges that is near a central value provided

Downloads

7

Readme

Build StatusCommitizen friendlyConventional CommitsBugsCode SmellsDuplicated Lines (%)Vulnerabilities

Quality Gate StatusCoveragenpmversion@masterDownloads@YearGitHub issues

array-groups

Tool to organize arrays of objects in sub-arrays grouped by value-ranges that is near a central value provided

Installation

npm install array-groups

Usage

array-groups can group any array of objects that have a numeric field in common. array-groups receives the main array, which contains the objects, and also checks an auxiliary array, which has the pure numeric values, in the same order as the array of objects, and also receives a value specifying a grouping range.

Example:

const group = require(array-groups);

let t1 = {
    value: 5,
    field: 'testing text',

}

let t2 = {
    value: 7,
    field: 'testing text',

}

let t3 = {
    value: 4,
    field: 'testing text',

}

let t4 = {
    value: 25,
    field: 'testing text',
    field2: 22
}

let t5 = {
    value: 21,
    field: 'testing text',

}

let t6 = {
    value: 44,
    field: 'testing text',

}

let t7 = {
    value: 48,
    field: 'testing text',

}

let t8 = {
    value: 55,
    field: 'testing text',

}

let t9 = {
    value: 59,
    field: 'testing text',

}

let t10 = {
    value: 50,
    field: 'testing text',

}

let testingArray = [ t1, t2, t3, t4, t5, t6, t7, t8, t9, t10 ]; // this is our Object Array that will be grouped in sub-arrays.

let valuesArray = []; // this is a numeric array containing the values to be grouped in the objects array as follows:

for ( let i = 0; i < testingArray.length; i++ ) {
    valuesArray.push( testingArray[ i ].value );
}

let range = 10; // grouping range


let grouped = group.GroupArray( testingArray, valuesArray, range );

That code should return a grouped array, that contain the sub-arrays already grouped. the grouped var should have this value:

[ 
    [   { value: 5, field: 'testing text' },
        { value: 7, field: 'testing text' },
        { value: 4, field: 'testing text' } 
    ],
    [ 
        { value: 25, field: 'testing text', field2: 22 },
        { value: 21, field: 'testing text' } 
    ],
    [ 
        { value: 44, field: 'testing text' },
        { value: 48, field: 'testing text' },
        { value: 55, field: 'testing text' },
        { value: 59, field: 'testing text' },
        { value: 50, field: 'testing text' } 
    ] 
]

Testing

run the unit test:

npm test