Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

array-lib

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

array-lib

A library for array functions in Array.prototype

  • 0.0.3
  • npm
  • Socket score

Version published
Weekly downloads
88
increased by66.04%
Maintainers
1
Weekly downloads
 
Created
Source

array-lib

A library for array functions in Array.prototype

Installation

npm install array-lib

Usage

 const arrayLib = require("array-lib");
 //deep copy a array:
 let arr = [1,2,3];
 let clone_arr = arr.clone();

 // Print an array:
 arr.print()//output [1,2,3]

 //Retrun max value from array and ignores elements that are not a number:
 console.log(arr.max());

 //Returns index of max value in array:
 console.log(arr.max_index());

//Removes element at specified position:
arr.remove(0);

arr.print()//Output: [2,3]

//Removes first or all values from array:
let a = [1,2,3,4,4,5,5];
let remove_all_elements = true;
a.remove_val(4,remove_all_elements);

a.print();//Output: [1,2,3,5,5];

//Count how much time a element is in a array
let b = ["a","b","b","c","b"];
console.log(b.count("b"));//Output: 3

//Replace elements in array

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

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

//Add up all numbers in array:
let d = [1,2,3,4,5];

console.log(d.add_up());//output: 15

//Create 2d array:
let arr = Array.matrix(2,3,"fill")
arr.print();
//Output:
//[ 
//    [ 'fill', 'fill', 'fill' ],
//    [ 'fill', 'fill', 'fill' ]
// ]

//Create array:

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

FAQs

Package last updated on 20 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc