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

@jitiendran/funarray

v1.0.2

Published

This is a npm package with fun and easy array operation

Downloads

3

Readme

funarray-package

This is the light weight array package with fun array manipulations and methods.

Get Started

npm install --save @jitiendran/funarray

Or if you're not into package management, just download a ZIP file.

Setup

After installing the package first the require the package from node modules into your javasctript file

const { FunArray } = require("@jitiendran/funarray");

Now, you can create a empty array by creating a object for the class FunArray.

let array = new FunArray();

You can also add element to array array while creating itself by doing the below.

let array = new FunArray(1, 2, 3, 4);

Common Operations

1. Create an Array

let fruits = new FunArray("Apple", "Bannana", "Orange");
let fruits = new FunArray();

fruits.push("Apple");
fruits.push("Bannana");

2. Access an Array elements

let fruit = fruits.atIndex(0); //returns value
const index = fruits.indexOf('Apple') //returns index

let fruit = fruits[index].

3. Looping through array

for (let i = 0; i < fruits.length(); i++) {
    console.log(fruits.atIndex(i));
}

Output

Apple
Bannana
Orange

4. Removing an item from last

fruits.pop(); //removes last item

console.log(fruits.array()); //converts funarray to array

Output

[ 'Apple', 'Bannana' ]

5. Remove an item from the beginning of an Array

fruits.shift(); //removes Apple from front

6. Add an item to the beginning of an Array

fruits.unshift("Strawberry");

//output: ['Strawberry','Bannana','Orange']
fruits.unshift('Strawberry','PineApple',...)

7. Remove an item by index position

fruits.removeAt(0); //removes the elements at index 0

8. Remove an item by value

fruits.remove("Apple"); //removes apple

9. Copy an array

let copy = fruits.slice();

10. Print fun array

fruits.print(); //prints the array

11. Convert Array to String

const str = fruits.toString();

12. Empty the whole array

fruits.trash();

13. Fill the array

fruits.fill("Avacado"); //fills everything with Avacado
fruits.fill("Avacado", 0, 1); //fills Avacado starting from index 0 upto 1

14. Merge with another array

let vegetables = new FunArray("Tomato", "Onion", "Brinjal");

fruits.merge(vegetables);

fruits.print();

Output

[ 'Apple', 'Bannana', 'Orange', 'Vegetables', 'Onion', 'Brinjal' ]

15. Make the Array distinct

let num = new FunArray(1, 2, 3, 3).distinct(); //returns normal array

console.log(num);
//output [1,2,3]

16. Remove the element from Object array using expression

let users = new FunArray(
    {
        _id: 1,
        Username: "Albert",
    },
    { _id: 2, Username: "Jason" }
);

users.removeWhere("_id === 1"); //expression should be string
console.log(users.array());

Output

[ { _id: 2, Username: 'Jason' } ]

17. Find the elements from Object array using expression

let users = new FunArray(
    {
        _id: 1,
        Username: "Albert",
    },
    { _id: 2, Username: "Albert" },
    { _id: 3, Username: "Jason" }
);

let foundUsers = users.findWhere("Username === Albert"); //returns normal array

console.log(foundUsers);

Output

[ { _id: 1, Username: 'Albert' }, { _id: 2, Username: 'Albert' } ]

18. Sort the Array in ascending Order

const num = new FunArray(4, 2, 3, 3);

let users = new FunArray(
    {
        _id: 2,
        Username: "Albert",
    },
    { _id: 1, Username: "Albert" },
    { _id: 3, Username: "Jason" }
);

num.sortAsc();

users.sortAsc("_id"); //sort by any key;

num.print();
users.print();

Output

[ 2, 3, 3, 4 ]
[
  { _id: 1, Username: 'Albert' },
  { _id: 2, Username: 'Albert' },
  { _id: 3, Username: 'Jason' }
]

19. Sort the Array in ascending Order

const num = new FunArray(4, 2, 3, 3);

let users = new FunArray(
    {
        _id: 2,
        Username: "Albert",
    },
    { _id: 1, Username: "Albert" },
    { _id: 3, Username: "Jason" }
);

num.sortDesc();

users.sortDesc("_id"); //sort by any key;

num.print();
users.print();

Output

[ 4, 3, 3, 2 ]
[
  { _id: 3, Username: 'Jason' },
  { _id: 2, Username: 'Albert' },
  { _id: 1, Username: 'Albert' }
]

20. Replace a item in the array

const names = new FunArray("Albert", "Albert", "Jason");

names.replace("Albert", "Happy"); // By default occurence is 1

console.log(names.array());

names.replace("Albert", "Happy", 2); //specifying occurence

console.log(names.array());

Output

[ 'Happy', 'Albert', 'Jason' ]
[ 'Happy', 'Happy', 'Jason' ]

21. Replace All elements in the array

const names = new FunArray("Albert", "Albert", "Jason");

names.replaceAll("Albert", "Happy");

Output

[ 'Happy', 'Happy', 'Jason' ]

22. Multiple push similar to creation

const names = new FunArray("Albert", "Albert", "Jason");

names.funPush("James", "Elric", "Alphonse");

names.print();

Output

[ 'Albert', 'Albert', 'Jason', 'James', 'Elric', 'Alphonse' ]

23. Find and Update the elements in array

const names = new FunArray("Albert", "Albert", "Jason");

names.findAndUpdate(0, "Alphonse");

names.print();

Ouput

[ 'Alphonse', 'Albert', 'Jason' ]