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-operations

v1.1.0

Published

This is JavaScript module for fastest array operations

Downloads

170

Readme

array-operations

array-operations is a JavaScript module which provides fastest functions for frequent array manipulation operations. These functions are tested against millions of elements in array and these are probably the fastest array manipulation functions present.

Installation

npm install array-operations

Usage

var array=require("array-operations");

min(arr);

Return minimum element present in the given array.

array.min ([1, -2, 3, -4, 5]); //-4
array.min (["a", "b", "c", "A"]); //A

max(arr);

Return maximum element present in the given array.

array.max ([1, -2, 3, -4, 5]); //5
array.max (["a", "b", "c", "A"]); //c

sum(arr);

Return sum of all the elements present in the given array.

array.sum ([1, 2, 3, 4, 5]); //15
array.sum (["array", "-", "operations"]); //array-operations

average(arr);

Return average of all the elements present in the given array.

array.average ([1, 2, 3, 4, 5]); //3

difference(arr1, arr2);

Return the difference of the given two array.

array.difference ([1, 2, 3, 4, 5], [4, 5]); //[1, 2, 3]
array.difference (["hello", "user", 3, 4, 5], ["user", 4]); // ["hello", 3, 5]

union(arr1, arr2);

Return the union of the given two array.

array.union ([1, 2, 3, 4, 5], [4, 5, 6, 7]); //[1, 2, 3, 4, 5, 6, 7]
array.union (["hello", "user", 3, 4, 5], [4, 5, "day"]); // ["hello", "user", 3, 4, 5,"day"]

intersection(arr1, arr2);

Return the intersection of the given two array.

array.intersection ([1, 2, 3, 4, 5], [4, 5, 6, 7]); //[4, 5]
array.intersection (["hello", "user", 3], ["user", "day"]); // ["user"]

removeDuplicates(arr);

Return the array with unique elements.

array.removeDuplicates ([1, 2, 2, 1, 3, 3, 4, 5]); //[1, 2, 3, 4, 5]
array.removeDuplicates (["hello", "user", "hello", 3, 3, 4]); // ["hello", "user", 3, 4]

filter(arr, function(item){ return (Boolean condition); });

Filter the given array with provided Boolean condition and returns the array containing all elements satisfying given Boolean condition.

array.filter ([1, 2, 3, 4, 5, 6], function(item){
	return (item%2===0);
}); //[2, 4, 6]

array.filter (["hello", "new", "user"], function(item){
	return (item<"new");
}); // ["hello"]

forEachPerform(arr, function(item){ return (action on every element of array); });

Performs the given action on every element in the given array and returns the array containing all elements performed given action.

array.forEachPerform ([1, 2, 3, 4, 5], function(item){
	return (item*2);
}); //[2, 4, 6, 8, 10]

array.forEachPerform (["hello", "new", "user"], function(item){
	return (item+" ok");
}); //["hello ok", "new ok", "user ok"]

areEqual(arr1, arr2);

Return true if the given two array are exactly same else return false.

array.areEqual ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]); //true
array.areEqual (["hello", "user", 3], ["hello", "user", 3]); // true
array.areEqual (["hello", "user", 3], ["hello", "user", 4]); // false

areDistinct(arr1, arr2);

Return true if the given two array are not exactly same else return false.

array.areDistinct ([1, 2, 3, 4, 5], [1, 3, 2, 4, 5]); //true
array.areDistinct (["hello", "user", 3], ["hello", "user", 4]); // true
array.areDistinct (["hello", "user", 3], ["hello", "user", 3]); // false

flatten(arr, level(this is optional parameter));

Return flatten array.

array.flatten ([1, 2, [3, 4, [5, 6], 10], 7, 8]); //[1, 2, 3, 4, 5, 6, 10, 7, 8]
array.flatten ([1, [2, [3, [4, 5, 6], 7], 8], 9], 2); // [1, 2, 3, [4, 5, 6], 7, 8, 9]