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

arrayed

v0.0.2

Published

utility function for arrays

Downloads

3

Readme

ARRAYED

arrayed is a utility for extending the array functionality.

Git Repository

https://github.com/chetansu/arrayed.git

Usage

install the package using npm command

$ npm i arrayed

The following functions are exposed in Arrayed.

arrayed.max()

max function takes in a single parameter in the form of array.

The response from this call is the maximum number in the array.

const arrayed = require(arrayed);

arrayed.max([20,22,15,9,8,15,22]);

returns

$ 22

arrayed.min()

min function takes in a single parameter in the form of array.

The response from this call is the minimum number in the array.

const arrayed = require(arrayed);

arrayed.max([20,22,15,9,8,15,22]);

returns

$ 8

arrayed.maxX()

maxX function takes in two parameters.

  • the array
  • first X largest numbers count

The response from this call is an array of unique largest number's of size X.

const arrayed = require(arrayed);

arrayed.maxX([20,22,15,9,8,15,22], 2);

returns

$ [22, 20]

arrayed.minX()

minX function takes in two parameters.

  • the array
  • first X Smallest numbers count

The response from this call is an array of unique Smallest number's of size X.

const arrayed = require(arrayed);

arrayed.minX([20,22,15,9,8,15,22], 3);

returns

$ [8, 9, 15]

arrayed.maxByRank()

maxByRank function takes in two parameters.

  • the array
  • rank of the largest number in the sorted array

The response from this call is a number of particular rank in the sorted unique array.

const arrayed = require(arrayed);

arrayed.maxByRank([20,22,15,9,8,15,22], 2);

returns

$ 20

arrayed.minByRank()

minByRank function takes in two parameters.

  • the array
  • rank of the smallest number in the sorted array

The response from this call is a number of particular rank in the sorted unique array.

const arrayed = require(arrayed);

arrayed.minByRank([20,22,15,9,8,15,22], 3);

returns

$ 15

arrayed.getUnique()

getUnique function takes in a single parameter in the form of array..

The response from this call is a unique unsorted array.

const arrayed = require(arrayed);

arrayed.getUnique([20,22,15,9,8,15,22]);

returns

$ [20,22,15,9,8]

arrayed.compare()

compare function takes in a two parameter in the form of arrays

The response from this call is a boolean.

const arrayed = require(arrayed);

arrayed.compare([20,22,15,9,8], [20,22,15,9,8]);

returns

$ true

arrayed.sortArray()

sortArray function takes in a two parameter

  • the array
  • increment or decremet the sort. increment is default

The response from this call is an incremented / decremented sorted array.

const arrayed = require(arrayed);

// Sort array incremented 
arrayed.sortArray([20,22,15,9,8,15,22]);
// Sort array decremented 
arrayed.sortArray([20,22,15,9,8,15,22], false);

returns

$ [22,22,20,15,15,9,8]
$ [8,9,15,15,20,22,22]

arrayed.getUniqueSorted()

getUnique function takes in a single parameter in the form of array..

The response from this call is a unique sorted array in increasing or decreasing order.

const arrayed = require(arrayed);

// Sort array incremented 
arrayed.getUniqueSorted([20,22,15,9,8,15,22]);
// Sort array decremented 
arrayed.getUniqueSorted([20,22,15,9,8,15,22]);

returns

$ [22,20,15,9,8]
$ [8,9,15,20,22]

arrayed.getCount()

getCount function takes in a two parameter

  • the array
  • the number to be searched
const arrayed = require(arrayed);

// getCount called with the searched number being available in array 
arrayed.getCount([20,22,15,9,8,15,22], 22);
// getCount called with the searched number not being available in array
arrayed.getCount([20,22,15,9,8,15,22], 27);

returns

$ 2
$ 0

for instantiation, you wil have to assign arrayed to a variable. A simple usage within the code is shown below.

const arrayed = require("./arrayed");

console.log("The largest number is " +arrayed.max([22,15,16,19,21,22]));
console.log("The smallest number is " +arrayed.min([22,15,16,19,21,22]));
console.log("The largest 2 numbers are " +arrayed.maxX([22,15,16,19,21,22], 2));
console.log("The smallest 3 numbers are " +arrayed.minX([22,15,16,19,21,22], 3));
console.log("The smallest 2nd number is " +arrayed.minByRank([22,15,16,19,21,22], 2));
console.log("The largest 3rd number is " +arrayed.maxByRank([22,15,16,19,21,22], 3));
console.log("On duplicate removal the array is " +arrayed.getUnique([22,15,16,19,21,22]));
console.log("On duplicate removal & sorting the array is " +arrayed.getUniqueSorted([22,15,16,19,21,22]));
console.log("On duplicate removal & sorting the array is " +arrayed.getUniqueSorted([22,15,16,19,21,22], false));
console.log("Sort Number array in decreasing order " +arrayed.sortArray([22,15,16,19,21,22], false));
console.log("Sort Number array in Increasing order " +arrayed.sortArray([22,15,16,19,21,22]));

Testing

To run the mocha test case. please install mocha and run the cases by using the command mocha.

$ npm install -g mocha
$ mocha

Calling arrayed functions
calling function max with array [20,22,15,9,8,15,22]      
Response recieved is 22
    ✔ expected array is 22
calling function min with array [20,22,15,9,8,15,22]      
Response recieved is 8
    ✔ expected array is 8
calling function maxX with array [20,22,15,9,8,15,22]     
Response recieved is 22,20,15
    ✔ expected array is 22,20,15
calling function maxX with array [20,22,15,9,8,15,22]     
Response recieved is 22,20
    ✔ expected array is 22,20
calling function minX with array [20,22,15,9,8,15,22]     
Response recieved is 8,9,15
    ✔ expected array is 8,9,15
calling function minX with array [20,22,15,9,8,15,22]     
Response recieved is 8,9
    ✔ expected array is 8,9
calling function maxByRank with array [20,22,15,9,8,15,22]
Response recieved is 15
    ✔ expected array is 15
calling function maxByRank with array [20,22,15,9,8,15,22]
Response recieved is 20
    ✔ expected array is 20
calling function minByRank with array [20,22,15,9,8,15,22]
Response recieved is 15
    ✔ expected array is 15
calling function minByRank with array [20,22,15,9,8,15,22]
Response recieved is 9
    ✔ expected array is 9
calling function getUnique with array [20,22,15,9,8,15,22]
Response recieved is 20,22,15,9,8
    ✔ expected array is 20,22,15,9,8
calling function getUniqueSorted with array [20,22,15,9,8,15,22]
Response recieved is 22,20,15,9,8
    ✔ expected array is 22,20,15,9,8
calling function getUniqueSorted with array [20,22,15,9,8,15,22]
Response recieved is 8,9,15,20,22
    ✔ expected array is 8,9,15,20,22
calling function sortArray with array [22,22,20,15,15,9,8]
Response recieved is 22,22,20,15,15,9,8
    ✔ expected array is 22,22,20,15,15,9,8
calling function sortArray with array [8,9,15,15,20,22,22]
Response recieved is 8,9,15,15,20,22,22
    ✔ expected array is 8,9,15,15,20,22,22


  15 passing (23ms)

NOTE

This library can be directly used with AWS lambda function to work as a microservice.

License

ISC Free Software, Hell Yeah!