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

v0.2.0

Published

A library for array functions in Array.prototype

Downloads

45

Readme

array-lib

A library for array functions in Array.prototype

Github

Installation

npm install array-lib

Usage


 const arrayLib = require("array-lib");

clone deep copy an array


let arr = [1,2,3];
let clone_arr = arr.clone();

print


arr.print();//=> [1,2,3]
"hello".print();// =>hello
(123).print();//=>123
{a:12}.print();//=>{a:12}

max Retrun max value from array


arr.max().print();

maxIndex Returns index of max value in array:


arr.maxIndex().print()

remove Removes element at the specified position


arr.remove(0);

arr.print()//=> [2,3]

removeVal Removes first or all values from array


let a = [1,2,3,4,4,5,5];
let remove_all_elements = true;
a.removeVal(4,remove_all_elements);

a.print();//=> [1,2,3,5,5];

count Count how much times a element is in an array


let b = ["a","b","b","c","b"];
console.log(b.count("b"));//=> 3

replace Replace elements in array


let c = [1,2,3,3,3,4,6,6,9];
c.replace(3,"d");

c.print();//=>[1,2,"d","d","d",4,6,6,9]

addUp Add up all numbers in array


let d = [1,2,3,4,5];

d.addUp().print();//=> 15

matrix Create a 2d array


let arr = Array.matrix(2,3,"fill")
arr.print();
//=>
//[ 
//    [ 'fill', 'fill', 'fill' ],
//    [ 'fill', 'fill', 'fill' ]
// ]

vector Create an array


let arr = Array.vector(6,"fill");
arr.print();//=> ['fill', 'fill', 'fill','fill', 'fill', 'fill']

toArray Create an array from a string


"hello ,world ,how ,are ,you".toArray().print();//=>
 //[ 'hello', 'world', 'how', 'are', 'you' ]

multiplyMatrices


let b = [[1,2],[3,4]]
b.multiplyMatrices([[1,4],[6,7]]).print()
//=>[ [ 13, 18 ], [ 27, 40 ] ]

isMatrix check if an array is a 2d matrix


 let matrix = [
     [0,1,2],
     [3,4,5],
     [6,7,8]
 ];

 matrix.isMatrix().print()// => true

avrage get Avrage from array


    [1,2,3,4,5].avrage().print();//=> 3

pos return first position of element in an array


  [1,2,3,4,5].pos(4).print();//=>3
  [1,2,3,4,5].pos(9).print();//=>false

getAllPos Get all positions of element in array


let arr = [1,3,4,4,8,7,5,3,4];
b.getAllPos(4).print();//=> [2,3,8]

shuffle shuffle an array


  [1,2,3,4,5,6,7,8,9].shuffle().print();
  //=> [ 7, 2, 9, 1, 6, 8, 3, 5, 4 ]

range A function to create flexibly-numbered lists of integers


Array.range(10);
//=> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Array.range(1, 11);
//=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Array.range(0, 30, 5);
//=> [0, 5, 10, 15, 20, 25]
Array.range(0, -10, -1);
//=> [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
Array.range(0);
//=> []

without Returns a copy of the array with all instances of the values removed.

let a = [1,2,3,1,2,31,2,31,1,2,3,]
let b = a.without(1,2);
b.print();
  //=>[ 3, 31, 31, 3 ]